parse text w/ line input

S

Steven Cheng

below is a copy of a port of the script from my listbox LSTBOX2, which lists
a set of text files in a particular directory and then goes through the file
line by line and extracts particular parts of wholeline for the field values.
for some reason, it isn't picking up the CR or CRLF.

I understand that Line Input relies on CR or CRLF to know where the
end/start of a line is so i believe that is why i see on the intermediate
window the complete file for wholeline variable rather than just one line,
right?

if that is the case, then how can i parse the data now?


If Me.lstBox2.ListCount > 0 Then
Set db = CurrentDb
Set rs = db.OpenRecordset("tblSalesDataDumpD+Migration")

For counter = 0 To Me.lstBox2.ListCount - 1

Open Me.lstBox2.ItemData(counter) For Input Access Read As #1

While Not EOF(1)
Line Input #1, wholeline
Debug.Print wholeline
MsgBox InStr(1, wholeline, Chr(10), vbBinaryCompare)
Select Case Mid(wholeline, 1, 3)
Case "DTL"
' If Val(Mid(wholeline, 28, 8)) <> 0 Then
With rs
.AddNew
!dtTransactionDate = CDate(dt) ' Transaction
or Business Date
!dtEffectiveDate = CDate(dt) 'effective date
of posting
!intStoreNumber = Int(Mid(wholeline, 4, 5))
' Store number Raw
!dbAmount = Val(Mid(wholeline, 28, 8)) '
Amount
If Mid(wholeline, 10, 5) = Mid(wholeline, 4,
5) Then
!strStoreAccount = Mid(wholeline, 15, 6)
' Account number for POS
!intGLCode = Val(Mid(wholeline, 15, 6))
' GL Coding
Else
!strStoreAccount = Mid(wholeline, 10, 6)
' Account number for POS
!intGLCode = Val(Mid(wholeline, 10, 6))
' GL Coding
End If
!strDescription = Trim(Mid(wholeline, 36,
40)) 'description
.Update
End With
' End If
Case "HDR"
dt = Mid(wholeline, 17, 2) & "/" & Mid(wholeline,
19, 2) & "/20" & Mid(wholeline, 15, 2)
End Select
Wend
Close #1
Next
rs.Close
db.Close
End If
 
S

Steven Cheng

okay, i understand why now. Didn't know that the text file was in unix
format and needs to be saved to PC or Dos.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top