944,030 Members | Top Members by Rank

Ad:
Feb 13th, 2007
0

Reading .dat file

Expand Post »
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.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim MyFile As String
  2. Dim FNo As Long
  3. Dim data() As String
  4. Dim fields As Integer
  5. Dim InLine As String
  6.  
  7. MyFile = "C:\Textlog\1_attlog.dat"
  8. On Error Resume Next
  9. Open "C:\Andoks\" & Format(Date, "MMDDYYYY") & ".txt" For Output As #1
  10. FNo = FreeFile
  11. If Dir(MyFile, vbDirectory) <> "" Then
  12. Open MyFile For Input As FNo
  13. While Not EOF(FNo)
  14. Line Input #FNo, InLine
  15. data() = Split(InLine)
  16. fields = UBound(data())
  17. 'Open "C:\Andoks\" & Format(Left(data(0), 10), "MMDDYYYY") & ".txt" For Output As #1
  18. 'Back Up "" Print #1, Format(Right(data(0), 10), "YYYY/MM/DD") & " " & Left(data(1), 8)
  19. Print #1, Format(data(1), "YYYY/MM/DD") & " " & Left(data(2), 8) & "," & " " & "Event:Access," & " " & "Door:1," & " " & "Card No.:" & Format(Right(data(0), 5), "00000")
  20.  
  21. Wend
  22. End If
  23. MsgBox "Attendance successfully downloaded ", vbInformation + vbOKOnly, "Record Saved"
  24. Unload Me
  25. Me.Show
  26. 'close
  27. Close #FNo
  28. Close #1
  29. Exit Sub
Similar Threads
Reputation Points: 13
Solved Threads: 1
Junior Poster in Training
royaloba is offline Offline
54 posts
since Sep 2006
Feb 14th, 2007
0

Re: Reading .dat file

So what's the problem? You should describe what's wrong so we know what were looking for.
Moderator
Reputation Points: 3278
Solved Threads: 894
Posting Sage
WaltP is offline Offline
7,747 posts
since May 2006
Feb 16th, 2007
0

Re: Reading .dat file

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)
Reputation Points: 13
Solved Threads: 1
Junior Poster in Training
royaloba is offline Offline
54 posts
since Sep 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Please Help me with Printing a record
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Please Help me with frmLogin





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC