Req: suggestions for reading fixed length fields from records in sequential files (newbie)

J

Jerry Higgins

Hi, im a beginner to programming, and my school allowed me to aquire a
academic version of msvs.net for private use.

being enrolled in the introductory programming class, I have been
assigned a project which involves reading data from a sequential file.
I would like to use vb.net to read the file and declare its records'
fields as variables, but im having problems.

I have heard something about reading each record as a whole, then
assigning the field length on each read on a per record basis. Any
suggestions?

I hope this isnt too stupid of a question, but some tips can be
helpful in conjunction with the msdn library and help system.

heres the structure of the input file, and the actual input file:

recStudent (52 characters) 'includes <LF> and <CR>
String Class (6 characters, CIS310, MTH101, or CS111 )
String Name (26 characters, "Last Name, First Name)
Character Withdrawn (1 character, "W")
Integer Minutes from School (3 characters, maximum of 75 minutes)
String Phone Number (14 characters, format "(999) 999-9999")

CIS310Blandings, Joseph 20 5865551386
CIS310Brewster, Jeaninne 30 5865557500
CIS310Driftwood, Jeffrey 20 5865550491
CIS310Eckland, Anthony 35 5865554153
CIS310Firefly, Steve 5 7395554541
CIS310Freneau, Kelley 20 5865553343
CIS310Fulton, John 5 5865556358
CIS310Hackenbush, Christopher 15 5865553468
CIS310Joshua, Julie 30 5865554362
CIS310Kerby, Candise 30 3135555344
CIS310Loophole, Christine 40 5865550500
CIS310Marie, Ervin 20 3135550194
CIS310Nugent, Janet 15 5865556416
CIS310Praetorius, Kerry 15 5865559700
CIS310Quale, Bradley 15 5865558263
CIS310Robie, Brandon 10 5865556234
CIS310Rochard, Kenneth 5 5865556018
CIS310Rutland, Melinda 30 5865554054
CIS310Sherman, Angela 15 5865551769
CIS310Spaulding, Matt 55 2485552339
CIS310Thornhill, Jennifer 15 5865550189
CIS310Wagstaff, Laura W 0
CS111 Claypool, Brandon 20 5865559475
CS111 Davis, Katie W 0
CS111 Dumont, William 35 5865553963
CS111 Eckland, Colleen 30 5865551893
CS111 Gould, Michael W 0

Any help will be much appreciated.

Thanks,
Jerry Higgins
 
M

Michael C#

Read in the file, one line at a time using a StreamReader. Use the
Substring() function to split up your line into separate variables.
Ideally, I would create a class that contains attributes that map to your
values; i.e.,

recStudent.Class = strLine.Substring(0, 6)
recStudent.Name = strLine.Substring(6, 26)
....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top