|
-
Jul 11th, 2008, 05:30 AM
#1
Thread Starter
New Member
Load txt file into listbox
Hi All
I need help with my application. Im using vb6 and Im trying to load values from text file into list box. I made everything right and the program is working fine but there is one issue which make me headache. When I'm loading the text file line by line into lstbox the program stop on line where is value PeterE . in the listbox appears Peter but the rest not and the lines after as well no showing. I know that the problem is the arrow but I need to see it all in the list box. I searched for solution on the internet but unlucky. I've one lstbox with name lstName on form with name frmEdit and im loading a text file with name file.txt
This is my code which I'm using to load the data:
Code:
Private Sub Form_Load()
Dim TextLine As String
Dim fn As Integer
Dim SourceFile As String
Dim path As String
path = App.path & "\Text Files\"
SourceFile = path & "file.txt"
frmEdit.lstName.Clear
fn = FreeFile
Open SourceFile For Input As #fn
Do While Not EOF(fn)
Line Input #fn, TextLine
frmEdit.lstName.AddItem (TextLine)
Loop
Close #fn
frmEdit.lstName.ListIndex = 0
End Sub
The content of the text file is:
Just example to work with
Peter Lach
Peter Lach
Peter Lach
Peter Lach
Peter Lach
Peter Lach
Peter Lach
Peter Lach
Peter Lach
Peter Lach
Peter Lach
Peter Lach
Peter Lach
PeterLach
Peter Lach
Peter Lach
Peter Lach
Peter Lach
Peter Lach
Peter Lach
Peter Lach
Peter Lach
Peter Lach
Peter Lach
Peter Lach
Peter Lach
Peter Lach
After loading everything after the arrow is not showing in the lstbox
Please help me with this
-
Jul 11th, 2008, 06:54 AM
#2
Re: Load txt file into listbox
Use binary mode and read whole file at once.
Code:
Dim TextLines() As String
' ...
Open SourceFile For Binary Access Read As #fn
TextLines = Split(Input(LOF(fn), fn), vbNewLine)
For lngA = 0 To UBound(TextLines)
frmEdit.lstName.AddItem TextLines(lngA)
Next lngA
Close #fn
I can't see the arrow character in your post.
-
Jul 14th, 2008, 02:52 AM
#3
Thread Starter
New Member
Re: Load txt file into listbox
Hi Merri
Thank you very much for your help it works now perfect!
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
|