Information générale
Titre:
Ending a do while loop
Deal All,
I am designing a form with a listbox and two command bottons, one
for starting a loop of measurement, the other for interrupting the
measurement.
When the button of starting measurement, a do loop is the activated,
and continue reading signal from rs232 port. outputing the signal to
the listbox. The other botton is used for ending the loop. What I hope
is no matter I press ESC key or the botton, the loop will be stopped.
The program I wrote as follows,
=======
*** When command button cmbtStartMeasure is clicked, starting measuring
action
** Step 1, open the port for receving data
If ThisForm.Comm.PortOpen=.F.
ThisForm.comm.portopen=.T.
Endif
** Step 2, Starting a loop reading data, until ESC is pressed
* Looping
* If ESC is pressed,
* then stoping measuring
* Otherwise:
* Checking whether the data in the input buffer
* reaches 13, which is the standard length
* of a piece of measurementthen
* Read data and show it in the EditBox, OutputData
* End Looping
Do while .T.
If ESC_PRESSED=.T.
EXIT
ENDIF
If ThisForm.comm.InBufferCount>=13
ThisForm.DataOutput.additem(ThisForm.comm.Input)
ThisForm.refresh
Endif
ENDDO
** Step 3: Close the port
IF ThisForm.Comm.PortOpen=.T.
ThisForm.comm.portOpen=.F.
ENDIF
=messagebox("stoping measurement, µ²§ô¶q´ú",0,"")
=========
And the code for the other botton as follows,
=========
IF ThisForm.Comm.PortOpen=.T.
ThisForm.comm.PortOpen=.F. && Close the port
ENDIF
=messagebox("stoping measurement, µ²§ô¶q´ú",0,"")
ThisForm.Release
Another procedure I wrote for this form, in the keyPress event follows
which sensors whether ESC is pressed for stoping the loop.
LPARAMETERS nKeyCode, nShiftAltCtrl
* When Escape Key is pressed, stoping measuring reading
If nKeyCode=27 && ESC pressed
ESC_PRESSED=.T.
ENDIF
However, each time when I run it, I cannot stop the by clicking on the
second botton. Especially, when there is no signal from the comm port,
the loop seems no ending. When I press the ESC key, one message shows
to interrupt the program, but doesn't seem caused by the procedure I
wrote.
Can someone check for me, and give me some suggestion.
Many thanks in advance, and looking forward for replies.
Best regards,
Ron.
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement