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??
Printable View
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??
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.
You could try this,
VB Code:
Dim txt As String Open "path.txt" For Input As #1 Do While Not EOF(1) Input #1, txt List1.AddItem txt Loop
In fact i don't think thats entirely what yur lookng for but it may be of some use.
Split function should work great. Just make sure your text file has a specific character that separates the lines (ex: comma, semicolon, etc...)
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:
Dim txt As String Open "path.txt" For Input As #1 Do While Not EOF(1) Input #1, txt List1.AddItem txt Loop close #1 'then(where x is the required line) EDIT : fixed a small mistake Dim i As Long Dim x As Long Dim j As Long x = Val(Text1.Text) ' for example With List1 For i = x To .ListCount - 1 List2.AddItem .List(i) If i = .ListCount - 1 And x > 0 Then For j = 0 To x - 1 List2.AddItem .List(j) Next j End If Next End With 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) .