I use length of file divided by record length to find the number of records, but although the record length shows correctly, the number of records is one more than it should be. Is that because LOF is incorrect? How can you tell? If you put a break point on it and let the cursor hover over that line nothing is shown as a value of LOF. The .dat file seems to be ok.
Open App.Path & "\Customers.dat" For Random As #1 Len = Len(Customer(Index))
NumberOfRecords = LOF(1) / Len(Customer(Index))
For Count = 1 to NumberOfRecords
Get #1, Count, Customer(Index)
Index = Index + 1
Next Count
Close #1
For i = 0 to Index
lstCustomerList.AddItem (Customer(i).CustomerID)
Next i
2006-11-15
22:41:29
·
1 answers
·
asked by
Older&Wiser
5
in
Computers & Internet
➔ Programming & Design
Thanks Rawlyn, but I had tried that whilst waiting for an answer. Instead of defining a MaxRecords variable I just used "For i = 0 to Index - 1" - but it doesn't help. Index was initialsed to zero before the open statement. You're right Index should finish being equal to the number of records, but it doesn't because NumberOfRecords is one too many and the loop goes through "1 to NumberOfRecords" times. So it goes through too many times, making index one higher than the number of records. And then index gets incremented, which now makes it 2 higher than the number of records instead of the expected 1 higher.
Any further help MUCH appreciated.
2006-11-16
00:41:31 ·
update #1
Problem solved - Rawlyn emailed me some ideas which lead to the solution. Thanks.
2006-11-16
02:22:45 ·
update #2