Import .txt file into vb6 project

Hello experts, is there any simple code to import text files delimited by TAB into a listbox in my visual basic project?

Lets say my .txt file contains...
========demo.txt==========
Australia [TAB] Greece [TAB] usa [TAB]
=========================

I need to retrieve Australia, greece and usa into a listbox seperate by line.
Carol2009Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HyperBPPCommented:
0
CIGHNCommented:
0
Rahul GuptaCommented:
Hope this helps you.....
Private Sub Form_Load()
Dim OneValue() As String

Open "c:\demo.txt" For Input As #1
Do Until EOF(1)
    Line Input #1, Data
    OneValue = Split(Data, vbTab)
    
    'Adding to Listbox, each records in seperate line
    With List1
        .AddItem OneValue(0)    'First Record
        .AddItem OneValue(1)    'Secord Record
        .AddItem OneValue(2)    'Third Record
    End With
Loop
Close #1

End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LeithauserCommented:
Is the entire file one long string delimited by tabs, or is it individual lines delimited by tabs and followed by a return?

If it is one continuous stream with no returns, then

DIm F as integer, S as String, L as Long, P As Integer, N as Integer
Redim MyArray(0) As String

F = Freefile
Open "demo.txt" for Binary as F
L = LOF(F)
S = Space$(L) ' This step may not be necessary
Get #F, L, S
Close F
P = Instr(S,chr$(9))
Do While P>0
    N=N+1
    Redim Preserve MyArray(N)
    MyArray(N) = Left$(S, P-1)
    S = Mid$(S,P+1)
    P = Instr(S,chr$(9))
Loop
 N=N+1
 Redim Preserve MyArray(N)
 MyArray(N) = S

If the file consists of individual strings followed by returns

DIm F as integer, S as String, L as Long, P As Integer, N as Integer
Redim MyArray(0) As String

F = Freefile
Open "demo.txt" for Input as F
Do Until EOF(F)
    Line Input #F, S
    P = Instr(S,chr$(9))
    Do While P>0
         N=N+1
         Redim Preserve MyArray(N)
         MyArray(N) = Left$(S, P-1)
         S = Mid$(S,P+1)
         P = Instr(S,chr$(9))
        Loop
        N=N+1
       Redim Preserve MyArray(N)
       MyArray(N) = S
Loop
Close F


0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.