hello Guys,

can somebody help me reading a .dat file then output the file in a textfile

sample .dat file

1 2007-02-12 18:13:13 1
1 2007-02-12 18:13:20 1
1 2007-02-12 18:13:23 1
1 2007-02-12 18:14:04 1
12345 2007-02-12 18:15:15 1
1 2007-02-12 18:15:17 1
12345 2007-02-12 18:15:19 1

sample Output
the content of the text file should have this kind of format.

2007/02/12 18:13:13, Event:Access Door:1, Card No.00001
2007/02/12 18:13:20, Event:Access Door:1, Card No.00001
2007/02/12 18:13:23, Event:Access Door:1, Card No.00001
2007/02/12 18:14:04, Event:Access Door:1, Card No.00001
2007/02/12 18:15:15, Event:Access Door:1, Card No.12345
2007/02/12 18:15:17, Event:Access Door:1, Card No.00001
2007/02/12 18:15:19, Event:Access Door:1, Card No.12345

here's the sample code.

Dim MyFile As String
Dim FNo As Long
Dim data() As String
Dim fields As Integer
Dim InLine As String

    MyFile = "C:\Textlog\1_attlog.dat"
    On Error Resume Next
    Open "C:\Andoks\" & Format(Date, "MMDDYYYY") & ".txt" For Output As #1
    FNo = FreeFile
    If Dir(MyFile, vbDirectory) <> "" Then
    Open MyFile For Input As FNo
     While Not EOF(FNo)
        Line Input #FNo, InLine
        data() = Split(InLine)
        fields = UBound(data())
        'Open "C:\Andoks\" & Format(Left(data(0), 10), "MMDDYYYY") & ".txt" For Output As #1
        'Back Up "" Print #1, Format(Right(data(0), 10), "YYYY/MM/DD") & " " & Left(data(1), 8)
        Print #1, Format(data(1), "YYYY/MM/DD") & " " & Left(data(2), 8) & "," & " " & "Event:Access," & " " & "Door:1," & " " & "Card No.:" & Format(Right(data(0), 5), "00000")
   
    Wend
    End If
    MsgBox "Attendance successfully downloaded       ", vbInformation + vbOKOnly, "Record Saved"
    Unload Me
    Me.Show
'close
    Close #FNo
    Close #1
Exit Sub

my sample code gives me a wrong output,
, Event:Access Door:1, Card No.:
, Event:Access Door:1, Card No.:
, Event:Access Door:1, Card No.:
, Event:Access Door:1, Card No.:
, Event:Access Door:1, Card No.:

my code doesn't read the data(0) and data(1)

This article has been dead for over six months. Start a new discussion instead.