Carol2009
asked on
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.
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.
This site tells you how to do this.
http://www.bigresource.com/VB-import-txt-file-data-into-access-database-S1rQBXIYRf.html
http://www.bigresource.com/VB-import-txt-file-data-into-access-database-S1rQBXIYRf.html
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
http://www.codenewsgroups.net/group/microsoft.public.vb.general.discussion/topic10958.aspx