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!")
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!