Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Possible to read Tab Delimited text file?

Status
Not open for further replies.

ahhuang

Programmer
Apr 1, 2002
61
SG
I have a text file and values are separated by tab.
How do i read these values using vb?
Thanx
 
brute-force way is to parse the input looking for CHR$(9), which is the <TAB> character. Use the INSTR function to find the first tab, hack off the first field, then call INSTR again with the startpos argument, to find the next tab. repeat until you run out of input.

Howard
 
Do you want to read them directly into a SQL database table by any chance? If so, you can do in one line of SQL using BULK INSERT. Not sure if any similar capability is available in Access.

If SQL is available to you, you could load into a temporary table to save yourself the parsing then do whatever you need with fields from the table.
 
? Split() function ?

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
You could also use DAO or ADO:

Private Function ReadTextFile(ByVal sPath As String, ByVal sFile As String) As DAO.Recordset
On Error GoTo fix_err
Dim Db As DAO.Database
Dim rs As DAO.Recordset
Set Db = OpenDatabase(sPath, False, True, &quot;Text; HDR=YES; IMEX=1;&quot;)
Set rs = Db.OpenRecordset(&quot;SELECT * FROM &quot; & sFile)
rs.MoveFirst
Set ReadTextFile = rs
Set rs = Nothing
Exit Function
fix_err:
MsgBox Err.Description + &quot; &quot; + _
Err.Source, vbCritical, &quot;Import&quot;
Err.Clear
End Function

Swi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top