title: do while condition vb6
body: <p>I have a little vb6 program:</p>
  
  <pre><code>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) &lt;&gt; "")
  
      string1 = varTemp(x)
      x = x + 1
  
      Loop
  
      Unload Form1
      End
  
  End Sub
  </code></pre>
  
  <p>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. </p>