StreamReader

VonEhle

Active member
Joined
Feb 20, 2006
Messages
26
Programming Experience
Beginner
I am taking a VB.Net class in school right now (college level). We are working on reading text files into an application. I am stuck on something and for the life of me can't figure out how to proceed. I know this should not be difficult... I'm obviously making it too hard.

Following is the text file...
11248 Reno Street,200,7
12/22/1995,150.8
12/1/1996,155.2
12/13/1997,158.4
12/8/1998,155.2
11/28/1999,166.5
11/28/2000,156.5
11/28/2001,165.5
1385 Foothills Drive,227,9
11/17/1993,150.8
12/19/1994,151.8
12/22/1995,153.8
12/1/1996,155.2
12/13/1997,158.4
12/8/1998,155.2
11/28/1999,166.5
11/28/2000,156.5
11/28/2001,165.5
8028 Rim Rock Drive,284,9
12/17/1993,250.8
11/19/1994,251.8
11/22/1995,253.8
12/1/1996,255.2
12/3/1997,258.4
12/8/1998,255.2
11/8/1999,266.5
11/2/2000,256.5
12/8/2001,215.5
828 Chamey Street,280,10
12/17/1992,253.2
12/17/1993,260.4
11/19/1994,271.2
11/22/1995,223.8
12/10/1996,255.2
12/3/1997,258.3
12/19/1998,255.6
11/8/1999,266.5
11/2/2000,256.5
12/8/2001,215.5

The program needs to read the address line first. The third number is the number of records that follow, and should be included with that address.

When this is output, it goes into three different list boxes. First box has the address from the first line. The second box gets the date. The third gets the number after the date.

All the other problems we did dealt with sequential files, so I'm not sure where to start with this problem since its different. Should the stream reader read the entire file first?
 
I had a feeling I'd answered this question but it appears not. Maybe it was at a different forum or perhaps I've just lost my grip. Anyway, the way you would do it is to use nested loops. You'd use an outer Do loop which would call the Peek method of a StreamReader and continue until it returned -1. You would read a line (StreamReader.ReadLine) and then split that line on the comma (String.Split). That will give you an array representing the elements of the first line. You can convert the last element to an Integer and use that to control an inner For loop, which can read the specified number of lines to get the dates, etc.
 
Back
Top