I have a project I'm working on in which I need to take a text file with an unknown number or lenth of names in it.
If there are 3 names on one line, the order is First name, Middle name, Last name... 2 names: First name, Last name... 1 name: last name. Then I need to post that into a listbox.
then (with a button) I need to take that name list and go line-by-line to rearrange them into "Last name, First name, Middle initial" and then alphabetically sort the lines and reprint into a listbox.
I tell you this so you can get an understanding of what my final goal is.
I guess to start with I'm having trouble actually even manipulating the string around... I'm starting to lose my focus here so I'll go ahead and post a clip of what I already have... this is one clip of many to come I think.
Dim result As DialogResult
Dim sr As IO.StreamReader
Dim numStr As String
Dim numlines, i As Integer
Dim lineList() As String
Dim openFileDialog As New OpenFileDialog()
result = openFileDialog.ShowDialog()
If result = Windows.Forms.DialogResult.OK Then
sr = IO.File.OpenText(openFileDialog.FileName)
numStr = sr.ReadLine
numlines = CInt(numStr)
ReDim lineList(numlines)
For i = 0 To numlines - 1
lineList(i) = sr.ReadLine
Next
For i = 0 To numlines - 1
LBXview.Items.Add(lineList(i))
Next
'lbOut.Sorted = True
sr.Close()
End If
(Rearangement will be done later)
As you can see I've set it up so there is a menustrip with an open file option. Once the file is selected and the OK button is pressed, I'm attempting to print the file out one line at a time... using a streamreader.readline to find out the number of lines and to print out X number of lines to the listbox (LBXview)
the problem is, when I execute this particular line of code I get an error saying something along the lines of "unable to convert string to integer" and points out the line of code numlines = CInt(numStr)
I'm a beginner to the VB language (or programming in general).... any ideas of what amazingly simple thing I messed up?


