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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Rahul GuptaConnect With a Mentor Commented:
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
 
HyperBPPCommented:
0
 
CIGHNCommented:
0
 
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
All Courses

From novice to tech pro — start learning today.