Reading .dat file

Reply

Join Date: Sep 2006
Posts: 54
Reputation: royaloba is an unknown quantity at this point 
Solved Threads: 1
royaloba royaloba is offline Offline
Junior Poster in Training

Reading .dat file

 
0
  #1
Feb 13th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: Reading .dat file

 
0
  #2
Feb 14th, 2007
So what's the problem? You should describe what's wrong so we know what were looking for.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 54
Reputation: royaloba is an unknown quantity at this point 
Solved Threads: 1
royaloba royaloba is offline Offline
Junior Poster in Training

Re: Reading .dat file

 
0
  #3
Feb 16th, 2007
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)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC