[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 320
  • Last Modified:

Exit a procedue by a keystroke in vb 6.0

I have a for loop in one of the command button code of the vb applicatoin. Is there a way I can exit this for loop my hitting some keys..I am looking for key_stroke process to end a for loop
0
Aiysha
Asked:
Aiysha
1 Solution
 
danaseamanCommented:
Try this. Uses Do/Loop but could be For/Next:

Option Explicit
 
Dim bEscape             As Boolean
 
Private Sub Command1_Click()
   Dim i                As Long
   Do
      DoEvents
      If bEscape Then
         bEscape = False
         Debug.Print "Exiting loop"
         Exit Do
      End If
   Loop
End Sub
 
Private Sub Form_KeyPress(KeyAscii As Integer)
   If KeyAscii = 27 Then
      bEscape = True
   End If
End Sub
 
Private Sub Form_Load()
   Me.KeyPreview = True
End Sub

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now