Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Order In Which Events Fire?? 1

Status
Not open for further replies.

dabineri

Programmer
Jun 20, 2001
265
0
0
US
In VB6 I have a checkbox and it seems that state of the checkbox (checked or not) has not changed when the MouseDown event fires but has changed when the MouseUp event fires.
I have a situation in which I need the original state of the checkbox to correctly save some data (a SAVE routing in the MouseDown event) and the new state of the checkbox to retreive some new data (a LOAD routine in the MouseUp event).
I seem to be running in to a timing issue. During the save of data can the MouseUp event occur thus changing what happens in my save routine? Can the state of the checkbox change while I am executing my save routine?
In other words if I have a checkbox and a SAVE routing and LOAD routine, what is the exact sequence of events when one clicks on the checkbox?
Is it, for example:
MouseDown Eevent Fires
SAVE routine executed
MouseUp event fires
LOAD routine executed?

Does the sequence depend on the time it take the SAVE or LOAD routine to execute?

This seems pretty basic but I am getting tangled up somewhere so I hope someone understands what I am trying to sort out here. Thanks for any help you can offer.
David Abineri


 
Easy way: Add a: debug.write "action performed" ... where action is each event.
 
Along those lines, I wrote a test:
Code:
Private Sub Check1_Click()
Debug.Print "click " & Check1.Value
End Sub

Private Sub Check1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Debug.Print "md " & Check1.Value
End Sub

Private Sub Check1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Debug.Print "mu " & Check1.Value
End Sub
whose result was (clicking the check box four times, starting with unchecked):
Code:
md 0
click 1
mu 1
md 1
click 0
mu 0
md 0
click 1
mu 1
md 1
click 0
mu 0
This suggests that the order of events is mousedown, click, mouseup, and that the value changes between the time the mousedown event fires and the click event fires. I noticed also that holding down the mouse button for a while has no effect on this outcome, and would finally observe that the double click event isn't handled by the checkbox.

I would think that the event handling procedures are synchronous; I would be surprised and interested to find that they were not. (If the mouseup event could fire before your mousedown code was finished, that would be asynchronous.)

Anyway, I would consider putting my save routine in the mousedown event and the load routine in the click or mouseup events.

HTH

Bob
 
Debug.Write, eh? That should work well under VB5/6 ...
 
It isn't a question of synchronicity. The window messages are routed through a FIFO queue so sequence is preserved.

I'm pretty sure the sequence of these mouse events is documented in the manual (Help) pretty explicitly too.
 
I was thinking more of Click Event.
Clicking a control generates MouseDown and MouseUp events in addition to the Click event. The order in which these three events occur varies from control to control. For example, for ListBox and CommandButton controls, the events occur in this order: MouseDown, Click, MouseUp. But for FileListBox, Label, or PictureBox controls, the events occur in this order: MouseDown, MouseUp, and Click. When you're attaching event procedures for these related events, be sure that their actions don't conflict.
 
<I'm pretty sure the sequence of these mouse events is documented in the manual (Help) pretty explicitly too.

Maybe, but I still prefer to mark them and test them.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top