December 19th, 2012, 01:45 AM
DoEvents executed when calling handler events manually??
I have a form with many standard controls on it, buttons, list boxes and a specific list box named List1 and a button Command1.
When user presses Command1 button, the program runs of course the Command1_Click handler. Also if the user clicks on the List1 box, the program executes List1_Click among other events (mousedown, mouseup etc).
Now, what is the thing i noticed. Inside the Command1_Click if i put lets say an endless loop 'Do ... blah blah... Loop' (for example), the user cannot click any object on the form because we trapped the instruction pointer in a loop.
In my code now. I have a Do..Loop making the List1.ListIndex go from down to up.
Do While (X>=0)
List1.ListIndex=X 'causes the List1_Click procedure to run on every selected item
List1_Click (setting listindex calls already the click event, but i need to run it twice for each item)
This loop takes about 10 seconds to execute (lots of work done inside the List1_Click handler, simple file operations only nothing strange).
While the loop is executing, the user can click in the form objects like the program is just waiting and not executing any other code! How come this is possible? And of course if the user clicks on an item in the List1 box, a runtime error appears saying "Still executing last request" !!! and the program terminates. I know we can stop this behavior by disabling/enabling the entire form or specific objects, but...
So, if calling manually a handler event, automatically (and thats sad) VB runs also some DoEvents (so the user can interruct with the form like nothing happends?).
- Better live in the digital world -
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!