944,065 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 11770
  • VB.NET RSS
Mar 14th, 2006
0

Homework: filling array from text file

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
harrypsk is offline Offline
2 posts
since Mar 2006
Mar 14th, 2006
0

Re: Homework: filling array from text file

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

VB.NET Syntax (Toggle Plain Text)
  1. dim data(999) as string 'initialise the array
  2. open "filename" for input as 1 'open the file
  3. for d% = 0 to 999 'start the loop
  4. if eof(1) = false then line input #1, data(d%) 'if the file hasn't ended read in the line
  5. next d% 'end the loop
  6. 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,
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
UberAAZ is offline Offline
73 posts
since Oct 2005
Mar 14th, 2006
0

Re: Homework: filling array from text file

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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
harrypsk is offline Offline
2 posts
since Mar 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Baffling Scroll bars
Next Thread in VB.NET Forum Timeline: VB 6 to internet programing whats the best way?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC