I have a little vb6 program:
Private Sub Form_Load()
Dim varTemp As Variant
Dim string1 As String
Dim x As Integer
x = 0
dialog.Filter = "toate fisierele(*.*) | *.*"
dialog.Flags = cdlOFNAllowMultiselect Or cdlOFNLongNames Or cdlOFNExplorer
'open the window to select files
dialog.ShowOpen
varTemp = Split(dialog.FileName, vbNullChar)
Do While (varTemp(x) <> "")
string1 = varTemp(x)
x = x + 1
Loop
Unload Form1
End
End Sub
I want the Do While to loop until it reaches the end of varTemp. However, when I choose two files from the dialog and “Do While” is hit with x = 3 I get “Run-time error ‘9’: Subscript out of range”. What condition should the “Do While” loop have to loop until the end of varTemp? Thank you.
You can use this instead:
Since
varTempwill be an array, this will loop until you hit the last element in the array.In case the user cancels the selection, and
varTempis empty, you may check for an empty string before looping, like this: