Results 1 to 5 of 5

Thread: List box data from text file??

  1. #1

    Thread Starter
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    List box data from text file??

    I have a text file as append... 64 items per line... I can read the first column of every line into a list box no prob, but how do I let the user select one item and have VB load in the 63 other items from that line into a series of control arrays??

  2. #2
    Lively Member
    Join Date
    Aug 2003
    Location
    Philadelphia, Pa.
    Posts
    123
    Use the Split function on the line of text you want to get into an array. The Split function will automatically split the text up into an array for you, you supply the delimeter, it will read it for you.
    Then load the array into whatever you want.

  3. #3
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959
    You could try this,

    VB Code:
    1. Dim txt As String
    2.  
    3.     Open "path.txt" For Input As #1
    4.     Do While Not EOF(1)
    5.         Input #1, txt
    6.         List1.AddItem txt
    7.     Loop

    In fact i don't think thats entirely what yur lookng for but it may be of some use.

  4. #4
    New Member
    Join Date
    May 2004
    Location
    Azores Islands, Portugal
    Posts
    4
    Split function should work great. Just make sure your text file has a specific character that separates the lines (ex: comma, semicolon, etc...)
    viaoceanica.com - Clicas? Clicas? Ou Não Clicas?

  5. #5
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959
    If you don't have a delim what i would do is load the text file into a listbox then load, starting at the required line, the data from that listbox to a second listbox.

    Something like this,

    VB Code:
    1. Dim txt As String
    2.  
    3.     Open "path.txt" For Input As #1
    4.     Do While Not EOF(1)
    5.         Input #1, txt
    6.         List1.AddItem txt
    7.     Loop
    8. close #1
    9.  
    10. 'then(where x is the required line)
    11.  
    12. EDIT : fixed a small mistake
    13.  
    14.  Dim i As Long
    15.   Dim x As Long
    16.   Dim j As Long
    17.   x = Val(Text1.Text)  ' for example
    18.    
    19.     With List1
    20.         For i = x To .ListCount - 1
    21.             List2.AddItem .List(i)
    22.             If i = .ListCount - 1 And x > 0 Then
    23.                 For j = 0 To x - 1
    24.                     List2.AddItem .List(j)
    25.                 Next j
    26.             End If
    27.         Next
    28.     End With
    29. End Sub

    or yuo could change the List2.AddItem .List(i) to List2.AddItem .List(x), dim an array myarray() as string, then add
    mayarray(i) = .list(i) in there and myarray(j) = .List(j) or myarray(i) = .List(j) .
    Last edited by Jmacp; May 14th, 2004 at 12:55 PM.

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