Search Tools Links Login

User Loop Break

Posted: 2019-09-25
By: MikeG
Viewed: 217

Filed Under:

Visual Basic 6, Visual Basic 6

No attachments for this post

If you have a long-running loop, you might want to give the user the ability to break out of the loop, in case they've changed their mind. This bit of code shows how to do that.


Private Declare Function GetAsyncKeyState Lib "user32.dll" _
    (ByVal vKey As Long) As Integer

Const VK_ESCAPE = &H1B
'//Button Click
Const VK_LBUTTON = &H1


Private Sub cmdStart_Click()
    If GetAsyncKeyState(VK_ESCAPE) < 0 Or _
    GetAsyncKeyState(VK_LBUTTON) < 0 Then
    Debug.Print "-------> EXIT <-------"
    Exit Do
    End If
    Debug.Print "______ LOOPING ___________"
End Sub

Special Instructions

This code originally appeared on, and has been republished here with the permission of Andrea Tincani.

Comments on this post

No comments have been added for this post.

You must be logged in to make a comment.