Homework: filling array from text file

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2006
Posts: 2
Reputation: harrypsk is an unknown quantity at this point 
Solved Threads: 0
harrypsk harrypsk is offline Offline
Newbie Poster

Homework: filling array from text file

 
0
  #1
Mar 14th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 73
Reputation: UberAAZ is an unknown quantity at this point 
Solved Threads: 1
UberAAZ's Avatar
UberAAZ UberAAZ is offline Offline
Junior Poster in Training

Re: Homework: filling array from text file

 
0
  #2
Mar 14th, 2006
Here's a little tip that should be enough to get you going (but not enough to do it for you )

  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,
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 2
Reputation: harrypsk is an unknown quantity at this point 
Solved Threads: 0
harrypsk harrypsk is offline Offline
Newbie Poster

Re: Homework: filling array from text file

 
0
  #3
Mar 14th, 2006
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?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC