Results 1 to 8 of 8

Thread: get the file contents

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    get the file contents

    what i want to do is for e.g., i have list.txt in my application directory so i want to loop through this file and get all the lines and put each entry into a list box, is this possible.?
    anyone have any sample code, would be very much appreciated!!

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: get the file contents

    i did this, but it just prints 5 zeros

    i want to put the entries into the list box

    VB Code:
    1. Private Sub Command3_Click()
    2. Dim fnum As Integer, one_line As String, lines As Long
    3.     fnum = FreeFile
    4.     Open "list.txt" For Input As #fnum
    5.     Do While Not EOF(fnum)
    6.         Line Input #fnum, one_line
    7.         'need to put the entries into list box
    8.         Debug.Print lines
    9.     Loop
    10.     Close fnum
    11. End Sub

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: get the file contents

    Try this
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim sData As String
    3. Dim sFilename As String
    4. sFilename = "c:\list.txt"
    5.  
    6. Open sFilename For Input As #1
    7. While Not EOF(1)
    8.     Line Input #1, sData
    9.     List1.AddItem sData
    10. Wend
    11. Close #1
    12.  
    13. End Sub

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: get the file contents

    ok thank you thats beautiful, is it also possible to now debug.print the number of entries in the list box?

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: get the file contents

    Quote Originally Posted by Pouncer
    ok thank you thats beautiful, is it also possible to now debug.print the number of entries in the list box?
    VB Code:
    1. Debug.Print List1.ListCount

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: get the file contents

    ok thank you very much Hack, now is it possible to debug.print for e.g. the 2nd entry in the list box? or 3rd etc

  7. #7
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: get the file contents

    each list entry has an index (starting at zero)

    Debug.Print List1.List(0) '1st item
    Debug.Print List1.List(1) '2nd
    Debug.Print List1.List(2) '3rd and so on
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: get the file contents

    Quote Originally Posted by Pouncer
    ok thank you very much Hack, now is it possible to debug.print for e.g. the 2nd entry in the list box? or 3rd etc
    VB Code:
    1. Debug.Print List1.List(2)

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