Click here to Skip to main content
15,898,926 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I have the following text file (ExamMarks.txt)

John, 85, 95, 90
Micheal, 60, 75, 75



I want to extract a line and take the Name and separately and the ints separately. Then I want to print the name and the average of the numbers like this in a label:

John's average is 90
Micheal's average is 70



So far I can only display what is in the text file in a label (see below):

Dim FILE_NAME As String = "C:\ExamMarks.txt"
    Dim TextLine As String

    If System.IO.File.Exists(FILE_NAME) = True Then

      Dim objReader As New System.IO.StreamReader(FILE_NAME)

      Do While objReader.Peek() <> -1
        TextLine = TextLine & objReader.ReadLine & vbNewLine

      Loop

      lblResults.Text = TextLine

    Else

      MsgBox("File Does Not Exist")

    End If


Any help is appreciated.
Posted

You need to first split the string based on the blank spaces that you find within it and store them in an array. You will then need to check if each of the alphanumeric characters within this array are numeric or string.
 
Share this answer
 
I had the code all typed out and was ready to submit, and then I realized that you were after VB6 code, so I deleted it. Tough nuts to you, bucko.

Besides all that, this is a homework assigment...
 
Share this answer
 
Comments
btap_644 1-Jul-10 15:08pm    
good guess. but i didnt ask u to do the coding for me perhaps a link to a sample would suffice like how william winner had given. Do appreciate you taking the time though, to answer.
So, you've figured out how to loop through and pull out each line.

When you pull out that line, you then need to search through each character and find the commas and get the text between them.

Or, you could just use the Split function (see here[^])
 
Share this answer
 
Comments
btap_644 1-Jul-10 15:07pm    
Thanks winner looks alot like it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900