michaelbrewitt
asked on
Getting data from text files
My programme puts scores in to a text file for each person. For example, one line might read:
Michael 10 8 9
I set up my own type in the general declarations part of my form:
Private Type PupilScores
strPupil As String * 50 'pupils name
strScoreE As String * 10 'number of easy q's asked
strScoreM As String * 10 'num of medium q's asked
strScoreH As String * 10 ' um of hard q's
End Type
I then set up the code to extract the scores for the person:
Sub Extract ()
dim PupilString as PupilScores
dim Score1 as integer
Open "file path" for input as #1
Do while not EOF(1) and PupilString.strPupil <> "Michael"
Input #1, PupilString
Score1 = PupilString.strScoreE
Loop
Msgbox Score1
End sub
i thought the message box should give me the score. But it gives me the name instead. How can I get this to work?
Thanks
Michael 10 8 9
I set up my own type in the general declarations part of my form:
Private Type PupilScores
strPupil As String * 50 'pupils name
strScoreE As String * 10 'number of easy q's asked
strScoreM As String * 10 'num of medium q's asked
strScoreH As String * 10 ' um of hard q's
End Type
I then set up the code to extract the scores for the person:
Sub Extract ()
dim PupilString as PupilScores
dim Score1 as integer
Open "file path" for input as #1
Do while not EOF(1) and PupilString.strPupil <> "Michael"
Input #1, PupilString
Score1 = PupilString.strScoreE
Loop
Msgbox Score1
End sub
i thought the message box should give me the score. But it gives me the name instead. How can I get this to work?
Thanks
ASKER
Yep. The file seemed fine. All on one line and taking up proper number of characters.
Do you use the UDT both for saving into the txt file and reading from it, or just for reading?
S
S
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If that isn't the problem I would but a breakpoint on the line 'Score1 = PupilString.strScoreE' and see what the value is. Also I would add a watch on PupilString so you can see what value is in each part of the type.