|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Excape Function
I have an application that is running and doing a bunch of calculations while running through a loop a specific number of times. RIght now when I hit the "GO" button it runs and I am forced to wait till the calculations are complete.
What I want to do is set a variable at the beginning of the loop that checks for a specific value. If True then it exits the code. Can I change that variable to True based off of a Keyboard entry. Say the user hits "Esc" on the next pass through the loop it would set the variable to True thus exiting the code. Is there a Keyboard Buffer? How do I access this Buffer to test for a specific value? THanks in Advance |
|
#2
|
||||
|
||||
|
Heres what you can do...
Make a textbox that is off the screen, but it must be enabled, and be visable. We will call it txtbox. before a loop takes place, set focus to the textbox: txtbox.SetFocus In the Txtbox event 'keydown' do an IF statement that detects the ESC key is pressed, and enter the command END into the statement results... Code:
Private Sub Txtbox_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 27 Then
End
End If
End Sub
So, what we have is a textbox that recieves focus while a calculation is taking place, and it will terminate the program when the ESC key (ascii 27) is pressed. This is un-proffesional and i'm not even sure if it will work, but keyboard buffers involve all sorts of API which I cant be arsed to go into. |
|
#3
|
|||
|
|||
|
This is a good idea and I can sort of get it to work. THe problem is that I have to have to cursor in the text box in order to get it to work.
While the code is running i hit the ESC key and nothing. Once the code stops I click in the text box and hit ESC and it works. THis is a bit confusing to me. Note: I got rid of the End and just used a message box. Private Sub txtbox_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 27 Then MsgBox "You are attempting to stop the code" End If End Sub Is there something I am doing incorrectly. The txtbox is visable and enabled I am setting the Focus before the loop, and tested it in the loop. Thanks for yor help |
|
#4
|
|||
|
|||
|
I had a similiar situation on a different program i was working on, Instead, put the code that needs to loop on the timer_tick sub, (make sure it's no longer a loop) and then keep a counter so it knows when to exit, and make sure it has to check that a boolean is true before it executes the code. Simply have a button on your form then that will turn the appropriate boolean to false and stop the timer. I found that setting the timer to tick every 200 ms. allows the system to interject commands but whatever code you have attached to the timer still runs nicely.
|
|
#5
|
|||
|
|||
|
I am quite new to the VB world. I think I understand what you wrote but am still a bit confused on the actual code.
1. Call timer_tick Sub from within the Loop 2. Once in the Timer_tick Sub start a timer, Set a boolean to True or false. If I stop the timer then does the code stops in the loop? How do you set the Boolean based on a Keyboard entry? THANK FOR YOU HELP HERE....IT IS APPRECIATED |
|
#6
|
|||
|
|||
|
Do you have a doEvents in the loop that does the calculating? If not, it may be the case that your txtbox doesn't get the message until the loop is done. Try that.
|
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Excape Function |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|