Reputation: 135
I must be overlooking something painfully obvious. The following code fails on the Next line with the error message "Expected end of statement":
Option Explicit
GetB
Sub GetB()
Dim i
For i = 1 to 2
Msgbox i
Next i
End Sub
Upvotes: 2
Views: 1757
Reputation: 135
Found it. The repetition of the loop variable ("i") in the Next statement, which is legal and optional in every other BASIC-like (B*SIC?) language, is illegal in VBS.
The code should read:
Option Explicit
GetB
Sub GetB()
Dim i
For i = 1 to 2
Msgbox i
Next
End Sub
Upvotes: 4