Read text file...help!

Hi,
I need to retrieve some data from a text file. Below is what I did but how could I retrieve student's name & result on history paper?

Results.txt
English Paper
Names Results
Chris 98
Jenny 66
Mark 73
Josh 64
Ella 70
Zinky 64
Stanley 55
Resttiey 30
Mathew 82

History Paper
Names Results
Chris 51
Jenny 88
Mark 64
Louis 70
Anthony 64

Codes
Dim iCount As Integer
Dim mySplitStr As String
Dim sLine As String
Dim strNames As String
Dim strResult As String

Open "C:\Results.txt" For Input As #1

Do Until EOF(1)
Line Input #1, sLine
iCount = iCount + 1

If iCount >= 3 Then
mySplitStr = Split(sLine, vbTab)
strNames = strNames + mySplitStr(0)
strResult = strResult + mySplitStr(1)
End If
Loop
Close #1

txtEngName.Text = strNames
txtEngResult.Text = strResult

txtHistName.Text = ??
txtHistResult.Text = ??
[1209 byte] By [lanne] at [2007-11-20 10:32:16]
# 1 Re: Read text file...help!
Well a few questions & comments that may guide you, as this sounds very much like a homework question..

1) - Are all the results in a single File? You will have to use a extra variable to hold what section of the file your busy with.. Dim bLoc as byte

If instr(1,sLine,"english",vbTextCompare) then bLoc = 1
If instr(1,sLine,"history",vbTextCompare) then bLoc = 2

2) - Are the names the same and in the same order for the next set of results ? Think about using an array to store the name and scores for each paper..Dim Name(40) as string ' Up to 40 students
Dim English(40) as Integer
Dim History(40) as Integer
Dim TmpLoop as Integer

'English Section
' We adding the names and scores to the array..
TmpLoop = TmpLoop +1
Name(TmpLoop) = mySplitStr(0)
English(TmpLoop) = mySplitStr(1)

'History Section..
'Names are in the list and we want to add the History scores...

For TmpLoop = 1 to 40
If Name(TmpLoop) = mySplitStr(0) Then History(TmpLoop) = mySplitStr(1)
Next TmpLoop

This should help you get the history results out...

Things to think about...

a) Adding a student in the history section who did not do a english paper..
b) Using "Redim Preserve" to expand the array as more students are added..
c) Adding other Subjects to the list..
d) Displaying the Name with all the relevent scores for each paper next to it...

Hope this gets you on the right track...

Gremmy...
GremlinSA at 2007-11-9 19:34:51 >
# 2 Re: Read text file...help!
thanks alot for your guide.
lanne at 2007-11-9 19:35:46 >