There are two fundamental problems with your algorithm.
The first is that once you have the keypress you do not
stop the process, rather you end the entire program.
Second, if the user presses E it is fine, but if s/he presses
e? You are not taking into account upper lower case
entries.
When you say that you want to "end a routine in a click event",
do you mean that when you click the button (assumiing it is a
button) the process starts and won't end until you press the E?
Or do you want to end the program when you press E? If you
want to end the program, is the process in the click event still
running or has it finishedor you simply don't care?
If all you want to do is end the program, then try these changes:
Private Sub Form_Keypress(KeyAscii As Integer)
Print KeyAscii
If (KeyAscii and 223) = 69 Then
unload me
end if
End Sub
If the process is still going, that is code is still executing in the
click
event, then you need something a little more elaborate:
private blnEndProcess as boolean
Private Sub Form_Keypress(KeyAscii As Integer)
Print KeyAscii
If (KeyAscii and 223) = 69 Then
blnEndProcess = true
end if
End Sub
This sets the flag that will tell the process to stop.
Now in the click event...
'You might something like
do
'Calibration code here. Somewhere in here you'll
'set the blnCalibrationDone flag, if at all.
'Now before the loop end do this:
doevents
'The above allows processing of other events,
'like for instance, the key press.
loop until blnCalibrationDone or blnEndProcess
'Now the question as to what you want to do after the calibration
'process is stopped. If you want to the program to wait till the
'user starts another calibration, then leave the next line commented.
'unload me
If you want the app to exit after calibration is ended, then remove the
comment from the last line. Note that the use of the End statement is
not recommended to end a program.
I hope this is useful to you, as there are some issues that you don't
mention, as the questions above indicate.
All of this is in addtion to what Karl recommends <g>
Good luck!!
Saga
"RC Bob" <
RCBob@discussions.microsoft.com>wrote in message
Quote
I am using VB6 to write programs to control some lab equipment. I am
trying
to read a keypress to end a routine in a click event. What I want is
to have
a label that says "Press 'E' to end the calibration" and return to
the Form1
main screen. The operator would then click another button to start
another
routine. How can I read a KeyPress and return the ascii code to use
in this
manner? I have used a sub to read a keypress on Form1 using
Private Sub Form_Keypress(KeyAscii As Integer)
Print KeyAscii
If KeyAscii=69 Then End
End Sub
This works but doesn't help me.
When I try to use the KeyAscii in my click event it won't do anything.
Can this be done?
Thanks,
RC Bob
-