title: IOException was unhandled. Bad file name or number
body: <p>I wrote this to read a selected index from a file and display its details but I'm having the error stated in the title.</p>
  
  <p>My code:</p>
  
  <pre><code>'Declare variables
  Dim OrdersFile As String
  Dim NumRecsFound As Integer
  Dim orderString As String
  Dim searchID As Integer
  
  'Find the selected order ID
  orderString = lstOrder.Text
  searchID = Val(Microsoft.VisualBasic.Left(orderString, 10))
  
  'Set up the path to the orders file
  OrdersFile = Application.StartupPath &amp; "/orders.dat"
  
  'Open the orders file in random access mode
  FileOpen(1, OrdersFile, OpenMode.Random, , , Len(OrderRec))
  'For each record in the file
  RecPos = 1
  'Read in every record until the end of the file is reached
  Do While Not EOF(1)
      FileGet(1, OrderRec, RecPos)
  
      'If the record matches selected order, display the order file
      If OrderRec.OrderID = searchID Then
          NumRecsFound = NumRecsFound + 1
  
          With OrderRec
              txtOrderID.Text = .OrderID
              txtOrderDate.Text = .OrderDate
              txtPrice.Text = .Price
              cmbCustomers.Text = .CustomerID
              cmbPizza.Text = .PizzaID
          End With
      End If
  
      'Lock fields until edit is selected
      txtOrderID.Enabled = False
      txtFee.Enabled = False
      txtOrderDate.Enabled = False
      txtStatus.Enabled = False
      txtPrice.Enabled = False
      cmbCustomers.Enabled = False
      cmbPizza.Enabled = False
  
      'Close the orders file and leave the subroutine
      FileClose(1)
  
      'If the records don't match then get the next record
      RecPos = RecPos + 1
  Loop
  
  'If no records are found then output message and close the file
  If NumRecsFound = 0 Then
      MsgBox("Order " &amp; searchID &amp; " could not be found. Please try again.")
      FileClose(1)
  End If
  FileClose(1)
  </code></pre>
  
  <p>the error appears in line 19; "Do While Not EOF(1)"</p>
  
  <p>Any help will be appreciated. Thanks.</p>