【发布时间】:2014-04-01 20:25:45
【问题描述】:
我写这篇文章是为了从文件中读取选定的索引并显示其详细信息,但我遇到了标题中所述的错误。
我的代码:
'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 & "/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 " & searchID & " could not be found. Please try again.")
FileClose(1)
End If
FileClose(1)
错误出现在第 19 行; “不做 EOF(1)”
任何帮助将不胜感激。谢谢。
【问题讨论】:
-
这是一个与您的问题没有直接关系的提示:如果您在 VB.NET 中编程,为什么要使用这么多 VB6 方法(比 .NET 旧得多)?如果你习惯用 VB6 编程,你可能会依赖一些 VB6 方法,但你的代码几乎是 100% VB6!
-
@varocarbas 写的一样,一个就够了
-
@Steve 好的。谢谢你让我知道(每个人都在这里提供不相关的建议,没有人解决实际问题哈哈)。
-
循环内的那个 FileClose ......嗯,没什么好说的。您的文件中有多少条记录?
-
@varocarbas 好的,谢谢。我是一名学生,有点遵循模板,但做一些我自己的事情。我的老师说我们在 vb.net 中编码。谢谢你告诉我。
标签: vb.net ioexception