|
-
May 14th, 2004, 10:30 AM
#1
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??
-
May 14th, 2004, 10:46 AM
#2
Lively Member
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.
-
May 14th, 2004, 11:05 AM
#3
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.
-
May 14th, 2004, 11:22 AM
#4
New Member
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?
-
May 14th, 2004, 11:31 AM
#5
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) .
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|