Click to See Complete Forum and Search --> : string manipulation and reading text files


mbw
October 19th, 2001, 04:39 PM
I want to be able to read in the contents of a text file into a list box, but I don't want to read everything in. The text file contains a header and 3 fields worth of data. All I want to do is read in the first column of data. For example, the text file looks like this:

age name sex
21 joe male
34 mary female
18 bill male
40 andy male

can anyone point me to some code that would allow me to read in the values of the age field only? in other words just list 21, 34, 18, and 40 in a listbox? thanks in advance.

PMS
October 19th, 2001, 11:27 PM
Try the below One
--------------------------------
Dim GetLine As String
Dim Position As Integer
Dim str As String
Open "C:\Sample.txt" For Input As #1
List1.Clear
While Not EOF(1)
Line Input #1, GetLine
Position = InStr(1, GetLine, " ")
If (Position > 0) Then
str = Left(GetLine, Position - 1)
List1.AddItem str
End If
Wend
Close #1