Vb.Net阵列帮助!!!! [英] Vb.Net Array Help!!!!
问题描述
我真的需要有人帮助这个项目,因为截止日期是明天! (我知道它有点晚了!)提前谢谢。
我正在尝试在vb.net中编写一个数组来保存记录位置的信息从几个列表框到.dat文件中的数组。我的问题是数据不会保存,我不断收到此错误:对象引用未设置为对象的实例在.JuiceID(i)
这是数组的代码:
Hi, I really need someones help on this project as the deadline is for tomorrow! (I left it a bit late I know!) Thanks in advance.
I'm trying to code an array in vb.net to save information at a record position from several listboxes into an array in a .dat file. My problem is the data will not save, and I keep getting this error: Object reference not set to an instance of an object at .JuiceID(i)
This is the code for the array:
For i = 0 To lstJuiceID.Items.Count - 1
With OrderItems
.JuiceID(i) = lstJuiceID.Items.Item(i)
.JuiceName(i) = lstJuiceName.Items.Item(i)
.Quantity(i) = lstQuantity.Items.Item(i)
.Total(i) = lstTotal.Items.Item(i)
.UnitPrice(i) = lstUnitPrice.Items.Item(i)
End With
OrderItems.CustomerID = lblID.Text
OrderItems.OrderNumber = lblOrderNumber.Text
Next
FileOpen(3, "OrderItems.dat", OpenMode.Random, , , Len(OrderItems))
RecordPosition = LOF(3) / Len(OrderItems)
RecordPosition = RecordPosition + 1
FilePut(3, OrderItems, RecordPosition)
FileClose(3)
MsgBox("Order Saved!") 'tells the user the order has been saved
这是OrderItems数据结构的代码:
and this is the code for the OrderItems Data Structure:
Module OrderItems
Public Structure OrderItemType
<VBFixedString(5)> Dim CustomerID As String
<VBFixedString(6)> Dim OrderNumber As String
<VBFixedString(6)> Dim JuiceID() As String
<VBFixedString(20)> Dim JuiceName() As String
Dim UnitPrice() As String
Dim Quantity() As String
Dim Total() As String
End Structure
End Module
你能帮助我吗?谢谢!
Can you help me? Thanks!
推荐答案
请阅读我对这个问题的评论。
你差不多完成了,试着完成它。看看这里:
结构和其他编程元素(Visual Basic) [ ^ ]
结构数组 [ ^ ]
它应该可以帮助您找到解决方案。
Please, read my comment to the question.
You're almost done, try to finish it. Have a look here:
Structures and Other Programming Elements (Visual Basic)[^]
Array of Structure[^]
It should help you to find solution.
这篇关于Vb.Net阵列帮助!!!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!