Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB 6 Read from sequential file into separate arrays

Status
Not open for further replies.

zara68

Technical User
May 7, 2015
1
0
0
GB
Hi - I have a text file containing student names and their exam marks:

Andrew Brown, 45
Carol Whyte, 67

etc

I need to read them into two separate arrays, one for the name and one for the exam mark. I am okay with reading from and writing to sequential files, but I don't know how to split each line, to separate the name into one array and the exam mark into another array.

Thanks!
 
You've pretty much answered your own question :)

Code:
Dim str As String

str = "Andrew Brown, 45"

MsgBox Split(str, ",")(0)
MsgBox Split(str, ",")(1)

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Seems awfully straightforward:

Code:
Dim F As Integer
Dim Count As Long
Dim RawLine As String
Dim I As Long
Dim Name() As String
Dim Mark() As Integer

'How big to make the arrays?  Guess we'll have to count since
'we have no header record to tell us!
F = FreeFile(0)
Open "marks-n-sparks.txt" For Input As #F
Do Until EOF(F)
    Line Input #F, RawLine
    Count = Count + 1
Loop

'Ok, on with the show:
ReDim Name(Count - 1), Mark(Count - 1)
Seek #F, 1
For I = 0 To Count - 1
    Input #F, Name(I), Mark(I)
Next
Close #F
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top