Hey guys/girls,
I am still working on my practice exam for tomorrow and have another question.
If I have a text file that I am reading with streamreader and it contains various entries, some are names and some are grades. The names are in the text file in the following format: Alice MacLeod
What I want to know is how I could read that line and output it to a listbox in the following format: MacLeod, A
Any help would be appreciated.
This is what I have, but I can't seem to figure out how to get the last name. I have declared some variables that are not used yet, just ignore them.
Quote:
Sub GetInfo()
Dim sr As IO.StreamReader
Dim name, fName, lName As String
Dim x, y, nameLength, space As Double
Dim numOfGrades As Double
sr = IO.File.OpenText("Lab5studentgrades.txt")
Do While sr.Peek <> -1
name = sr.ReadLine
nameLength = CDbl(name.Length)
lName = name.Substring(name.IndexOf(" "), nameLength - 1)
fName = name.Substring(0, 1)
lstOutput1.Items.Add("Name: " & lName & ", " & fName)
Loop
End Sub
