Link to home
Start Free TrialLog in
Avatar of michaelbrewitt
michaelbrewittFlag for United Kingdom of Great Britain and Northern Ireland

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
Avatar of jmwheeler
jmwheeler

Did you open your input file and make sure that the input is right?  Name taking up 50 characters, ScoreE taking up the next 10, etc,  All on the same line.

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.
Avatar of michaelbrewitt

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
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial