Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Is this the best Continue in a loop of VB6

Featured Replies

Posted

There's no continue directive in VB6.

Is this code below is the best (shortest) solution?

  Dim i As Integer  For i = 1 To 5
If i = 3 Then
GoTo CNT
End If
Print i
CNT:
Next

Edited by alaphate

Check out this page on MSDN:

http://msdn.microsoft.com/en-us/library/t2at9t47(VS.80).aspx

It explains the following snippet:

Sub exitStatementDemo()
Dim demoNum As Single
' Set up an infinite loop.
Do
For i As Integer = 1 To 10000000
demoNum = Int(Rnd() * 100)
Select Case demoNum
Case 7 : Exit For
Case 29 : Exit Do
Case 54 : Exit Sub
End Select
Next i
Loop
End Sub

Basically you can use "Exit For" to break out of a "For" loop. Im not sure how applicable this is to VB6, as i dont program in either VB6 or VB .NET.

Just installed VB6 to check it out and it had a problem with declaring i as an integer if i left it as part of the For declaration and it wasnt happy with such a large integer, but changing it to:

Sub exitStatementDemo()
Dim demoNum As Single
Dim i As Integer ' Set up an infinite loop.
Do
For i = 1 To 10000
demoNum = Int(Rnd() * 100)
Select Case demoNum
Case 7 : Exit For
Case 29 : Exit Do
Case 54 : Exit Sub
End Select
Next i
Loop
End Sub

Then it compiled fine...

HR,

Ghandi

Edited by ghandi

  • Author

Ghandi,

Thanks for the code.

However, Exit For just like c++ break

It break out from the FOR loop

In my sample code, It will print out: 1 2 4 5

and skip 3, so when i=3, it will continue the loop

  Dim i As Integer  For i = 1 To 5
If not i = 3 Then
Print i
End If Next

It could be done like this also. This just means that the default case isnt 3, so it will execute the code inside the "If not" statement and only jumps over the code when i=3.

HR,

Ghandi

Edited by ghandi

  • Author

Ghandi,

Your code is better than mine :)

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.