CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2001
    Location
    MA
    Posts
    11

    string manipulation and reading text files

    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.


  2. #2
    Join Date
    Oct 2001
    Location
    India
    Posts
    16

    Re: string manipulation and reading text files

    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




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured