PDA

View Full Version : [SOLVED] Keep code running in mouse up event



Roldy
01-24-2020, 11:33 AM
I have some text boxes with code that I need to keep running as long as I am in that text box. The user would click on a text box and select their object (in the application). After selecting the object, the user shouldn't have to click on the text box again to select a different object if they so choose to. Also, the user should have the freedom to select a different text box (which would have the same type of code, with minor variances). My first attempt was something as shown below in pseudo code.


textboxA_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

Do While selected object count < 2
DoEvents
*Process Selection*
If valid selection then
display information about selection on form
End If
Exit Do
Loop

TextBoxA_MouseUp 1, 0, X, Y

End Sub

This type of code would be used for textboxB with some differences in the Process Selection bit. Setting focus to the text box won't work since it does not trigger the Do While loop. I would need some way to run the Do While loop again, even after a valid selection. Maybe I need to nest the Exit Do in an If Then that checks to see if any of the other text boxes have the ActiveControl.TabIndex. If the condition is true, then I exit the current mouse event sub. The question I have with this is that once I click on another text box, will I get moved to that text box before I'm able to make a decision based on the ActiveControl.TabIndex value?

SamT
01-25-2020, 12:22 PM
Dim tbxA_MouseUp_IsRunning as Boolean
Dim tbxB_MouseUp_IsRunning as Boolean


Private Sub textboxA_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

tbxB_MouseUp_IsRunning = False
tbxA_MouseUp_IsRunning = True

Do While tbxA_MouseUp_IsRunning
Do While selected object count < 2
DoEvents
*Process Selection*
If valid selection then
display information about selection on form
End If
Exit Do
Loop
Loop
TextBoxA_MouseUp 1, 0, X, Y

End Sub


Private Sub textboxB_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)

tbxA_MouseUp_IsRunning = False
tbxB_MouseUp_IsRunning = True


Do While tbxB_MouseUp_IsRunning
Do While selected object count < 2
DoEvents
*Process Selection*
If valid selection then
display information about selection on form
End If
Exit Do
Loop
Loop
TextBoxB_MouseUp 1, 0, X, Y

End Sub

Roldy
01-25-2020, 01:11 PM
Thank you, this worked.