Yes, this is homework, I'm not asking for a cut/past answer, just a pointer. I think I've developed brain lock form staring at this issue for too long. I'm using VB.Net 2003.

I've created half the assignment, using a form to add records to a text file. The second half is to read from that text file. You do so by selecting the id number from a combo box which then displays the remainder of the information for the record. I'm stuck on how to create an array, filled with values from the text file. Not sure how to proceed with reading only the id number for the combo, and then reading the remainder once the combo is used. Yes, a database would be easier, but this assignment requires the use of a text file. I understand the use of StreamReader, I guess I'm stuck on the loop function to read data into an array, and then displaying the items from the array.

The data in the text file looks like this:

Record ID 1
Data 1
Data 1
Data 1
Record ID 2
Data 2
Data 2
Data2

Thanks to anyone who takes a stab at giving me a few pointers.

Here's a little tip that should be enough to get you going (but not enough to do it for you ;))

dim data(999) as string 'initialise the array
open "filename" for input as 1 'open the file
for d% = 0 to 999 'start the loop
if eof(1) = false then line input #1, data(d%) 'if the file hasn't ended read in the line
next d% 'end the loop
close 1 'close the file, it's messy to have it open

That's reading stuff into an array. To display it, perhaps you could use the ItemIndex (or whatever it's called) property and read data from the array like data(list.ItemIndex)?

Hope that makes sense,

That was one point I wasn't sure about, now to handle an unknown length for the array. It's variable as there will be no telling how many lines and records will be in the text file. You used 999 to initialize, but the loop checks for end of file, so the array begins at 999 elements, but could actuall only have 20 if that's all the text file contains, correct?

This article has been dead for over six months. Start a new discussion instead.