CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2001
    Location
    Toronto, CANADA
    Posts
    16

    Text File Read and Display

    Hi gurus...

    I have a text file with following contents:
    "abc", 123, xyz
    "lmn", 345, qrs
    "abc", 999, asd

    I want to display "abc", "lmn", "abc" in a combo list box... and when clicked on "abc" from the list box, I wanna be able to display the correspondeing text such as "123, xyz" into a picture box or a textbox.

    Any ideas as to how i can link the first part of a line in a text file with the rest of the line?

    Looking for some code.. Much much appreciated.

    [n]Shaikh
    | http://nawedshaikh.com |

  2. #2
    Join Date
    Apr 2000
    Posts
    737

    Re: Text File Read and Display

    First you need to read the whole file into string (ReadFileStr), then you need to separate the string into individual line (Tokenize, GetToken), finally you need to use the mid$ function on individual string.

    get those function (ReadFileStr, Tokenize, GetToken) from

    http://vblib.virtualave.net


  3. #3
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Text File Read and Display


    private sub form_load()
    dim Str1(100) as string, str2(100) as string, str3(100) as string, str as string
    dim arr
    dim filenum as long
    dim cnt as integer
    filenum=freefile
    open "data.txt" for input as #filenum
    cnt = 0
    do while not EOF(filenum)
    line input #filenum, str
    arr = split(str,",")
    str1(cnt)=arr(0)
    combo1.additem str1
    str2(cnt)=arr(1)
    str3(cnt)=arr(2)
    cnt = cnt+1
    loop
    end sub

    private sub combo1_click()
    dim indx as integer
    indx = combo1.listindex
    text1.text = str2(indx)
    text2.text = str3(indx)
    end sub





  4. #4
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Text File Read and Display

    Another way to do this

    option Explicit
    Dim Arr1(10) as string
    Dim arr2(10) as string

    private Sub Combo1_Click()
    Text1 = Arr1(Combo1.ListIndex)
    Text2 = arr2(Combo1.ListIndex)
    End Sub

    private Sub Command1_Click()
    Dim Temp as string
    Dim X as Integer
    Open "C:\VB Stuff\Things to Look at\Test.txt" for input as #1
    Do Until EOF(1)
    input #1, Temp, Arr1(X), arr2(X)
    Combo1.AddItem Temp
    X = X + 1
    Loop
    End Sub




    John G

  5. #5
    Join Date
    Mar 2001
    Location
    Toronto, CANADA
    Posts
    16

    Re: Text File Read and Display

    Thank you so much guys/gals... you all are great! btw, your ratings just went up! : )

    [n]Shaikh
    | http://nawedshaikh.com |

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