Importing dat file with both text and tab delimited columns

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a .dat file that has both regular text and tab delimited columns. I
have been using Infile.readline and then InStr function with code like this
to import the regular text not in a column format.

Do Until strsampleID = "Sample ID"
strsampleID = Infile.readline
If InStr(strsampleID, "Sample ID") Then
startpos = InStr(strsampleID, ":")
sampleID = Trim(Mid(strsampleID, startpos + 1, 13))
reslab = Trim(Mid(strsampleID, startpos + 31, 4))
expdate = Trim(Mid(strsampleID, startpos + 60, 14))
Exit Do
that all works fine to get the data and then i have more code to put into
the appropriate tables.

I am not sure how to write the code for the next part. It looks like this
and it is tab delimited between the columns:

CT RN CCC RT
1 1 0.00 4.5666
24 3 222.56 66.444
306 2 33.33 0.0000
1111 4 2.333 229.999

I don't know how to tell it what position in the line to start from to get
the data into the variable and then into the table. Any help would be
appreciated. Thanks.

Michele
 
Not overly elegant, but try this code snippet to split the line into an
array and then loop through the array (this code snippet assumes that you've
read in the entire line as strFullLine):

Dim intLoop As Integer, intValues As Integer
Dim strFullLine As String
Dim varValues As Variant
' code that reads entire line into strFullLine goes here
'
varValues = Split(strFullLine, " ")
intValues = -1
For intLoop = 0 To 3
Do
intValues = intValues + 1
If varValues(intValues) <> "" Then
Select Case intLoop
Case 0
CTField = Val(varValues(intValues))
Case 1
RNField = Val(varValues(intValues))
Case 2
CCCField = Val(varValues(intValues))
Case 3
RTField = Val(varValues(intValues))
End Select
Exit Do
End If
Loop
Next intLoop
 
Back
Top