hello every one..
good day...
first i was able find the solution in this site on how to open the textfile and save it to the
database, i'm using mysql as my database...thanks to sir "jomet" ;) . now what i want to do is, i want to
open a muntiple text file and save it to database...my project is to create a time and attendance
system base on the textlog creates by biometic time and attendance device...this device creates a
daily textlog which the file name base on date i.e.10102006, 10112006, 10122006... (that is the exact
format of the filename) as i mention i was able to open a textfile but, one textfile only..what i want
to do is, i will create a datepicker then, when i select a date i.e october 10 to 12.. all the
textfile that is in the range of the selected date, and it will save to the database...
the textlog is located at C:\textlog\... please give me a sample code, as my guide..i need help guru..

try to see the sample textlog bellow

sir Yomet

help me sir i'm stuck with my project...my problem is how to open a multiple text file and load it to a single master file...i already have the code how to read multiple text file but the problem is when i write the text file it returns the file name that i open i.e. i open in "C:\textlog\" the file name is text1, text2, text3. it returns the file name with .txt at the end of the file, what i want to happen is to put the content of the all text files that i open in one master file....here's my sample code sir

Private Sub Form_Load()
  Const START_PATH = "C:\Textlog\"
   Dim sFileName As String
   Dim sBuffer As String
   Dim iFile As Integer

   sFileName = Dir$(START_PATH & "*.txt")
   Do While Len(sFileName) > 0
      'Open/Read and Close
      iFile = FreeFile
      Open START_PATH & sFileName For Input As iFile
      sBuffer = Input(LOF(iFile), iFile)
      'Close iFile
      'Replace all occurances
      'Open/Write and close
      iFile = FreeFile
      Open "C:\output.txt" & sFileName For Output As iFile
      Print #iFile, sBuffer
      Close iFile
      'Get the next file
      sFileName = Dir$
   Loop
  End Sub

-----------------------------------------------------------
or do you have any idea how to insert a code to open a multiple text file
the code that you give to me sir, it's working nice, but again sir, it allows to open a 1 text file at a time...
my text files is located at "C:\textlog" please help with this sir, i don't have any idea to fix this sir..

Dim inFile As Integer
    Dim InLine As String
    Dim data() As String
    Dim fields As Integer
    Dim sFile As String
    'sFile = txtFile.Text
    sFile = Text1.Text
    inFile = FreeFile

    Open sFile For Input As #inFile
    Set conn = New ADODB.Connection
    conn.Open "DRIVER={MySQL ODBC 3.51 Driver};" & "SERVER=localhost;" & " DATABASE=time_and_attendance;" & "UID=root;PWD=admin; OPTION=3"
    While Not EOF(inFile)
        Line Input #inFile, InLine
        If InStr(InLine, "Event:Access") > 0 Then
        data() = Split(InLine)
        fields = UBound(data())
             
        Set rs = New ADODB.Recordset
        squery = "": squery = "Select * from tblattendance where Date='" & data(0) & "' AND CardNumber='" & Card(data(5)) & "'"
        rs.Open squery, conn
        If rs.EOF Then
        conn.Execute "INSERT INTO tblattendance (Date, CardNumber, TimeIn) " & _
                     "VALUES ('" & data(0) & "', " & _
                          "'" & Card(data(5)) & "', " & _
                           "'" & Format(Left(data(1), 8), "hh:mm:ss AM/PM") & "')"
                           
        
        Else
            conn.Execute "UPDATE tblattendance set TimeOut = '" & Format(Left(data(1), 8), "hh:mm:ss AM/PM") & "'  where Date='" & data(0) & "' AND CardNumber='" & Card(data(5)) & "'"
        End If
        rs.Close
        Set rs = Nothing
        End If
    Wend

    MsgBox "Record successfully saved       ", vbInformation + vbOKOnly, "Record Saved"
    Unload Me
    Me.Show 1
    Close #inFile
    Exit Sub

Royaloba,

Like last time I will answer your question here in the public forum where everyone can use the information.

If I have understood you well you want to merge several text files into one. Is that correct?

If so your solution is actually quite simple, you simply Dim oFile As Integer and use the FreeFile function to get a valid file number for it. Something like this:

Private Sub Form_Load()
  Const START_PATH = "C:\Textlog\"
   Dim sFileName As String
   Dim sBuffer As String
   Dim iFile As Integer
   Dim oFile As Integer

   oFile = FreeFile
   Open "C:\Textlog\output.txt" For Output As oFile
   sFileName = Dir$(START_PATH & "*.txt")
   Do While Len(sFileName) > 0
      'Open/Read and Close
      iFile = FreeFile
      Open START_PATH & sFileName For Input As iFile
      sBuffer = Input(LOF(iFile), iFile)
      Close iFile
      'Replace all occurances
      'Open/Write and close
'      iFile = FreeFile
'      Open "C:\output.txt" & sFileName For Output As iFile
'      Print #iFile, sBuffer
'      Close iFile
      Print #oFile, sBuffer
      'Get the next file
      sFileName = Dir$
   Loop
   Close oFile
  End Sub

What happens here is that you open the output file first and keep it open for the duration of the loop, therefore you can always write to it without overwriting what is already in it. The Open <filename> For Output As <filenumber> actually overwrites a file if it exists already, you would that have to use the "For Append" in order to write without overwriting. However, if you keep the output file open all the time you don't have to worry about Output or Append.

In general you can open as many files as you want (almost) as long as you have a variable for each file you want to open, i.e. you could have

Dim File1 As Integer
Dim File2 As Integer
Dim File3 As Integer
Dim File4 As Integer
Dim File5 As Integer
Dim File6 As Integer
...
...
...
Dim File100 As Integer
Dim File101 As Integer
Dim File102 As Integer

and then open each one of these files at the same time for input, output, append or binary as you see fit. Now don't quote me on the exact number of files you can open at the same time, I don't know the exact number but the help file most probably does, otherwise someone in the forum does, I'm sure.

From what I can see the second code snippet you included was the solution to your first problem and is now working fine from what you said.

Hope this helps, if not just reply to this post and I will be notified.

Happy coding

Yomet

Hi,

Say ur datepicker is dtpk_F, dtpk_T
code u need to write is,

Dim FromDate As Date
Dim ToDate As Date
Dim MyDate As Date
Dim MyFile As String
Dim FNo As Long

FromDate = Format(dtpk_F.Value,"dd-mm-yyyy")
ToDate = Format(dtpk_T.Value,"dd-mm-yyyy")
MyDate = FromDate
Do
MyFile = "C:\textlog\" & Format(MyDate,"ddmmyyyy") & ".txt"
FNo = FreeFile
Open MyFile For Input As FNo
' Do ur processing here
Close FNo
'
MyDate = MyDate + 1
'
Loop Until MyDate >= ToDate

If u have doubts, u can get back to me.

Regards
Veena

veena,
thanks for you quick response....;) i got the rigth output that i want.. but there is only few bugs...
first when i select a date i.e. 11012006 to 11302006 there is a error, when the textfile is not present in the textlog directory i.e. 11052006, 11082006... and if i select a date 11012006 to 11302006 the return value is up to 11292006 only, i will attach the sample ;)
thanks again

Hi,

To check if file is present or not, u can use this code,

If Dir(MyFile, vbDirectory) <> "" Then
' Open File Here
' Do Text Processing Here
' Close File Here
End If

Regards
Veena

Veena,
hello, i add a field in the database named total TotalHours, i add this to compute the difference time of TimeIn and TimeOut, but i have a hardtime doing it, i didn't know where is my error try to see the sample. hope you can help me again..thanks

Hi,

U have To create TotalHours As a Date/Time Field Only.

I have Access 97 here , so was not able to open ur Database.

Any way try this SQL Statement to calculate Total Hours:

Update tblAttandence Set TotalHours = CDate(TimeOut) - CDate(TimeIN) Where TimeOut IS Not Null And Date=#01-01-2005' And CardNo='5'

If u still have problems, feel free to contact me.

Regards
Veena

Hi,
Sorry that was

Update tblAttandence Set TotalHours = CDate(TimeOut) - CDate(TimeIN) Where TimeOut IS Not Null And Date=#01-01-2005# And CardNo='5'

Regards
Veena

Veena,
thanks for you quick response, your given code is working well in access, but when i use in mysql it's give a error "FUCNTION CDate does not exist" do have any idea about it..? thanks again..

Hi,

Yes, I had Given that For Access.
For MySQL use this function.

Update tblAttandence Set TotalHours = SubTime(TimeOut, TimeIn)

and give where condition as usual.

Regards
Veena

Hi,

"You Ask Veena And It Shud Work, There is no question of not working"

Any Problems Regarding VB/Oracle/SQL/Crystal Reports/Queries
u r free to ask

Regards
Veena

Veena,
Hello
this is for my other project which i have to donwload all the attendance from the biometric device, then saved it to "C:\TNA\" .txt
as text files, this is sample the code

Dim dwEnrollNumber As Long
    Dim dwVerifyMode As Long
    Dim dwInOutMode As Long
    Dim timeStr As String
    Dim iDate As Date
    Dim i As Long
    Dim TempLine As String
    iDate = Date
    

    dwEnrollNumber = 1
    CZKEM1.ReadAllGLogData 1
        i = i = 1
    Open "C:\TNA\" & Format(iDate, "mmddyyyy") & ".txt" For Output As #1
    While CZKEM1.GetGeneralLogDataStr(1, dwEnrollNumber, dwVerifyMode, dwInOutMode, timeStr)
        'i = i + 1
       
        If dwInOutMode = 0 Then
            iInOut = "Event:Access,"
            Else
            iInOut = "Event:Access,"
        End If
        
        Print #1, Format(timeStr, "YYYY/MM/DD HH:MM:SS,") & " " & iInOut & " " & "Door:entry," & " " & "Card No.:" & Format(dwEnrollNumber, "00000") & ","
        
            i = i + 1
    Wend
    MsgBox "Attendance successfully downloaded"
    Close 1

THE SAMPLE DOWNLOADED FILE, file name is "12022006" .txt

2006/11/29 15:37:39, Event:Access, Door:entry, Card No.:00001,
2006/11/29 15:37:42, Event:Access, Door:entry, Card No.:00012,
2006/11/29 15:38:42, Event:Access, Door:entry, Card No.:00001,
2006/11/29 15:38:45, Event:Access, Door:entry, Card No.:00012,
2006/11/29 15:38:57, Event:Access, Door:entry, Card No.:00123,
2006/11/29 15:39:00, Event:Access, Door:entry, Card No.:01234,
2006/11/29 15:39:03, Event:Access, Door:entry, Card No.:12345,
2006/11/29 15:39:05, Event:Access, Door:entry, Card No.:00001,
2006/11/29 15:39:11, Event:Access, Door:entry, Card No.:00012,
2006/11/29 15:39:17, Event:Access, Door:entry, Card No.:00123,
2006/11/29 15:52:06, Event:Access, Door:entry, Card No.:00001,
2006/11/29 15:54:08, Event:Access, Door:entry, Card No.:00012,
2006/11/29 15:54:31, Event:Access, Door:entry, Card No.:33333,
2006/11/29 15:55:09, Event:Access, Door:entry, Card No.:33333,
2006/11/29 15:55:29, Event:Access, Door:entry, Card No.:00012,
2006/11/29 15:55:45, Event:Access, Door:entry, Card No.:00012,
2006/11/29 15:55:51, Event:Access, Door:entry, Card No.:00012,
2006/11/29 15:55:55, Event:Access, Door:entry, Card No.:33333,
2006/11/29 15:56:01, Event:Access, Door:entry, Card No.:00123,
2006/11/29 15:57:07, Event:Access, Door:entry, Card No.:00012,
2006/11/29 15:57:12, Event:Access, Door:entry, Card No.:33333,
2006/11/29 15:57:15, Event:Access, Door:entry, Card No.:00123,
2006/11/29 15:57:18, Event:Access, Door:entry, Card No.:01234,
2006/11/29 15:57:21, Event:Access, Door:entry, Card No.:12345,
2006/11/29 15:57:35, Event:Access, Door:entry, Card No.:00001,
2006/11/29 15:57:42, Event:Access, Door:entry, Card No.:00001,
2006/11/29 15:57:50, Event:Access, Door:entry, Card No.:00012,
2006/11/29 15:57:52, Event:Access, Door:entry, Card No.:33333,
2006/11/29 15:57:55, Event:Access, Door:entry, Card No.:00123,
2006/11/29 15:58:48, Event:Access, Door:entry, Card No.:33333,
2006/11/29 15:58:51, Event:Access, Door:entry, Card No.:00012,
2006/11/29 15:58:54, Event:Access, Door:entry, Card No.:33333,
2006/11/29 15:58:57, Event:Access, Door:entry, Card No.:00001,
2006/11/29 15:59:06, Event:Access, Door:entry, Card No.:00012,
2006/11/29 15:59:20, Event:Access, Door:entry, Card No.:00012,
2006/11/29 15:59:32, Event:Access, Door:entry, Card No.:00012,
2006/11/29 15:59:37, Event:Access, Door:entry, Card No.:33333,
2006/11/29 16:00:11, Event:Access, Door:entry, Card No.:00012,
2006/11/29 16:01:11, Event:Access, Door:entry, Card No.:01234,
2006/11/29 16:01:21, Event:Access, Door:entry, Card No.:00001,
2006/11/29 16:01:29, Event:Access, Door:entry, Card No.:00012,
2006/11/29 16:01:32, Event:Access, Door:entry, Card No.:33333,
2006/11/29 16:01:35, Event:Access, Door:entry, Card No.:00123,
2006/11/29 16:01:38, Event:Access, Door:entry, Card No.:01234,
2006/11/29 16:01:41, Event:Access, Door:entry, Card No.:00012,
2006/11/29 16:01:43, Event:Access, Door:entry, Card No.:33333,
2006/11/29 16:01:45, Event:Access, Door:entry, Card No.:00123,
2006/11/29 16:01:48, Event:Access, Door:entry, Card No.:01234,
2006/11/29 16:01:50, Event:Access, Door:entry, Card No.:00012,
2006/11/29 16:01:52, Event:Access, Door:entry, Card No.:33333,
2006/11/29 16:01:55, Event:Access, Door:entry, Card No.:00123,
2006/11/29 16:02:05, Event:Access, Door:entry, Card No.:00001,
2006/11/29 16:02:14, Event:Access, Door:entry, Card No.:00012,
2006/11/29 16:02:16, Event:Access, Door:entry, Card No.:33333,
2006/11/29 16:03:05, Event:Access, Door:entry, Card No.:00001,
2006/11/29 16:07:00, Event:Access, Door:entry, Card No.:00012,
2006/11/29 16:07:37, Event:Access, Door:entry, Card No.:00012,
2006/11/29 16:07:40, Event:Access, Door:entry, Card No.:33333,
2006/11/29 16:07:44, Event:Access, Door:entry, Card No.:00123,
2006/11/29 16:07:47, Event:Access, Door:entry, Card No.:01234,
2006/11/29 16:07:53, Event:Access, Door:entry, Card No.:12345,
2006/11/29 16:07:57, Event:Access, Door:entry, Card No.:00001,
2006/11/29 16:08:14, Event:Access, Door:entry, Card No.:00001,
2006/11/29 16:08:56, Event:Access, Door:entry, Card No.:00001,
2006/11/29 16:09:16, Event:Access, Door:entry, Card No.:00001,
2006/11/29 16:09:24, Event:Access, Door:entry, Card No.:00012,
2006/11/29 16:09:27, Event:Access, Door:entry, Card No.:33333,
2006/11/29 16:10:16, Event:Access, Door:entry, Card No.:00012,
2006/11/29 16:10:22, Event:Access, Door:entry, Card No.:33333,
2006/11/29 16:10:25, Event:Access, Door:entry, Card No.:00123,
2006/11/29 16:10:27, Event:Access, Door:entry, Card No.:01234,
2006/11/29 16:10:31, Event:Access, Door:entry, Card No.:12345,
2006/11/29 16:10:34, Event:Access, Door:entry, Card No.:00001,
2006/11/29 16:11:01, Event:Access, Door:entry, Card No.:00123,
2006/11/29 16:11:04, Event:Access, Door:entry, Card No.:01234,
2006/11/29 16:11:07, Event:Access, Door:entry, Card No.:00012,
2006/11/29 16:11:21, Event:Access, Door:entry, Card No.:00001,
2006/11/29 16:12:05, Event:Access, Door:entry, Card No.:00012,
2006/11/29 16:12:08, Event:Access, Door:entry, Card No.:33333,
2006/11/29 16:12:11, Event:Access, Door:entry, Card No.:00123,
2006/11/29 16:12:14, Event:Access, Door:entry, Card No.:01234,
2006/11/29 16:12:17, Event:Access, Door:entry, Card No.:00123,
2006/11/29 16:12:19, Event:Access, Door:entry, Card No.:33333,
2006/11/29 16:12:50, Event:Access, Door:entry, Card No.:00012,
2006/11/29 16:12:52, Event:Access, Door:entry, Card No.:33333,
2006/11/29 16:13:49, Event:Access, Door:entry, Card No.:33333,
2006/11/29 16:14:17, Event:Access, Door:entry, Card No.:00012,
2006/11/29 16:14:21, Event:Access, Door:entry, Card No.:33333,
2006/11/29 16:14:23, Event:Access, Door:entry, Card No.:00123,
2006/11/29 16:14:26, Event:Access, Door:entry, Card No.:01234,
2006/11/29 16:14:30, Event:Access, Door:entry, Card No.:00012,
2006/11/29 16:14:36, Event:Access, Door:entry, Card No.:33333,
2006/11/29 16:14:38, Event:Access, Door:entry, Card No.:00123,
2006/11/29 16:16:23, Event:Access, Door:entry, Card No.:00001,
2006/11/29 16:16:25, Event:Access, Door:entry, Card No.:00001,
2006/11/29 16:16:29, Event:Access, Door:entry, Card No.:00001,
2006/11/29 16:16:35, Event:Access, Door:entry, Card No.:00012,
2006/11/29 16:16:38, Event:Access, Door:entry, Card No.:33333,
2006/11/29 16:16:41, Event:Access, Door:entry, Card No.:00123,
2006/11/29 16:36:48, Event:Access, Door:entry, Card No.:00001,
2006/11/29 16:37:25, Event:Access, Door:entry, Card No.:00001,
2006/11/29 16:38:25, Event:Access, Door:entry, Card No.:33333,
2006/11/29 16:38:51, Event:Access, Door:entry, Card No.:00001,
2006/11/29 16:39:25, Event:Access, Door:entry, Card No.:00001,
2006/11/29 16:39:58, Event:Access, Door:entry, Card No.:00001,
2006/11/29 16:43:52, Event:Access, Door:entry, Card No.:00001,
2006/11/29 16:45:06, Event:Access, Door:entry, Card No.:00012,
2006/11/29 16:45:52, Event:Access, Door:entry, Card No.:00123,
2006/11/29 16:46:29, Event:Access, Door:entry, Card No.:01234,
2006/11/29 16:47:22, Event:Access, Door:entry, Card No.:00123,
2006/11/29 16:50:09, Event:Access, Door:entry, Card No.:00012,
2006/11/29 16:50:12, Event:Access, Door:entry, Card No.:33333,
2006/11/29 16:50:15, Event:Access, Door:entry, Card No.:00123,
2006/11/29 16:50:18, Event:Access, Door:entry, Card No.:01234,
2006/11/29 16:50:22, Event:Access, Door:entry, Card No.:00012,
2006/11/29 16:50:25, Event:Access, Door:entry, Card No.:33333,
2006/11/29 16:50:28, Event:Access, Door:entry, Card No.:00123,
2006/11/29 16:50:40, Event:Access, Door:entry, Card No.:00001,
2006/11/29 19:11:58, Event:Access, Door:entry, Card No.:00001,
2006/11/30 09:06:48, Event:Access, Door:entry, Card No.:00002,
2006/11/30 09:07:24, Event:Access, Door:entry, Card No.:00002,
2006/11/30 09:08:35, Event:Access, Door:entry, Card No.:00003,
2006/11/30 09:09:18, Event:Access, Door:entry, Card No.:00001,
2006/11/30 09:09:29, Event:Access, Door:entry, Card No.:00004,
2006/11/30 09:10:03, Event:Access, Door:entry, Card No.:00001,
2006/11/30 09:10:07, Event:Access, Door:entry, Card No.:00005,
2006/11/30 09:12:39, Event:Access, Door:entry, Card No.:00008,
2006/11/30 09:13:46, Event:Access, Door:entry, Card No.:00009,
2006/11/30 09:14:10, Event:Access, Door:entry, Card No.:00008,
2006/11/30 09:14:50, Event:Access, Door:entry, Card No.:00010,
2006/11/30 09:14:56, Event:Access, Door:entry, Card No.:00010,
2006/11/30 09:15:07, Event:Access, Door:entry, Card No.:00005,
2006/11/30 09:16:23, Event:Access, Door:entry, Card No.:00002,
2006/11/30 09:17:56, Event:Access, Door:entry, Card No.:00006,
2006/11/30 09:22:54, Event:Access, Door:entry, Card No.:00005,
2006/11/30 09:31:18, Event:Access, Door:entry, Card No.:00002,
2006/11/30 09:31:23, Event:Access, Door:entry, Card No.:00002,
2006/11/30 09:31:34, Event:Access, Door:entry, Card No.:00004,
2006/11/30 09:35:18, Event:Access, Door:entry, Card No.:00002,
2006/11/30 09:35:24, Event:Access, Door:entry, Card No.:00002,
2006/11/30 09:35:38, Event:Access, Door:entry, Card No.:00009,
2006/11/30 09:36:35, Event:Access, Door:entry, Card No.:00009,
2006/11/30 09:38:24, Event:Access, Door:entry, Card No.:01234,
2006/11/30 15:08:15, Event:Access, Door:entry, Card No.:01234,
2006/11/30 15:08:21, Event:Access, Door:entry, Card No.:01234,
2006/11/30 15:11:00, Event:Access, Door:entry, Card No.:00001,
2006/11/30 15:11:15, Event:Access, Door:entry, Card No.:00001,
2006/11/30 17:22:13, Event:Access, Door:entry, Card No.:00001,
2006/11/30 17:22:18, Event:Access, Door:entry, Card No.:00011,
2006/11/30 17:26:19, Event:Access, Door:entry, Card No.:00001,
2006/11/30 17:26:23, Event:Access, Door:entry, Card No.:00012,
2006/11/30 17:26:27, Event:Access, Door:entry, Card No.:33333,
2006/11/30 17:26:31, Event:Access, Door:entry, Card No.:00123,
2006/11/30 17:26:34, Event:Access, Door:entry, Card No.:01234,
2006/11/30 17:26:37, Event:Access, Door:entry, Card No.:12345,
2006/12/02 09:56:46, Event:Access, Door:entry, Card No.:01234,
2006/12/02 09:56:55, Event:Access, Door:entry, Card No.:00012,
2006/12/02 09:57:00, Event:Access, Door:entry, Card No.:12345,
2006/12/02 09:57:05, Event:Access, Door:entry, Card No.:12345,
2006/12/02 09:57:43, Event:Access, Door:entry, Card No.:12345,
2006/12/02 09:58:01, Event:Access, Door:entry, Card No.:54321,

what i want to happen is after i download the attendance i want to sepate the file base on there date i.e. 2006/11/29 , 2006/11/30, 2006/12/02 then save it, the file name also base on there date i.e. 12022006..and also every time a download the attendance it's over write the existing file textfile, it should not over write the existing textfile

Hi,

Ok,

If u open a file for Outoput, the file is over-written instead use Append.
In Append Mode, the data is updated to the existing File. If the File does not exist, then new one is created.
Its always a good programming practice to use FreeFile to Get the Number.

Dim FN As Long
FN = FreeFile
Open "C:\TNA\" & Format(iDate, "mmddyyyy") & ".txt" For Append As #FN
' Do the Coding Here
Close #FN


After this as usual use open the file in the loop, use Append Mode to create the files.

If u get stuck with the coding, then let me know, Post the project, i will modify and post it back.

Regards
Veena

Veena,
thanks, you've solve my 2nd problem, but still my main problem is if i will download all the attendance from the reader it will save only in one file..this is the sample output file... the file name is base on the date i download the file...12052006.txt

2006/12/01 10:53:40, Event:Access, Door:1, Card No.:00011,
2006/12/01 10:53:49, Event:Access, Door:1, Card No.:00010,
2006/12/01 11:01:17, Event:Access, Door:1, Card No.:00010,
2006/12/01 11:01:19, Event:Access, Door:1, Card No.:00011,
2006/12/01 11:03:03, Event:Access, Door:1, Card No.:00012,
2006/12/01 11:03:05, Event:Access, Door:1, Card No.:33333,
2006/12/01 11:03:07, Event:Access, Door:1, Card No.:00123,
2006/12/01 11:03:09, Event:Access, Door:1, Card No.:01234,
2006/12/01 11:04:51, Event:Access, Door:1, Card No.:00015,
2006/12/01 11:05:18, Event:Access, Door:1, Card No.:00016,
2006/12/01 11:05:56, Event:Access, Door:1, Card No.:00015,
2006/12/01 11:05:58, Event:Access, Door:1, Card No.:00016,
2006/12/01 11:06:39, Event:Access, Door:1, Card No.:00015,
2006/12/02 10:53:40, Event:Access, Door:1, Card No.:00011,
2006/12/02 10:53:49, Event:Access, Door:1, Card No.:00010,
2006/12/02 11:01:17, Event:Access, Door:1, Card No.:00010,
2006/12/02 11:01:19, Event:Access, Door:1, Card No.:00011,
2006/12/02 11:03:03, Event:Access, Door:1, Card No.:00012,
2006/12/02 11:03:05, Event:Access, Door:1, Card No.:33333,
2006/12/02 11:03:07, Event:Access, Door:1, Card No.:00123,
2006/12/02 11:03:09, Event:Access, Door:1, Card No.:01234,
2006/12/02 11:04:51, Event:Access, Door:1, Card No.:00015,
2006/12/02 11:05:18, Event:Access, Door:1, Card No.:00016,
2006/12/02 11:05:56, Event:Access, Door:1, Card No.:00015,
2006/12/02 11:05:58, Event:Access, Door:1, Card No.:00016,
2006/12/02 11:06:39, Event:Access, Door:1, Card No.:00015,
2006/12/03 10:53:40, Event:Access, Door:1, Card No.:00011,
2006/12/03 10:53:49, Event:Access, Door:1, Card No.:00010,
2006/12/03 11:01:17, Event:Access, Door:1, Card No.:00010,
2006/12/03 11:01:19, Event:Access, Door:1, Card No.:00011,
2006/12/03 11:03:03, Event:Access, Door:1, Card No.:00012,
2006/12/03 11:03:05, Event:Access, Door:1, Card No.:33333,
2006/12/03 11:03:07, Event:Access, Door:1, Card No.:00123,
2006/12/03 11:03:09, Event:Access, Door:1, Card No.:01234,
2006/12/03 11:04:51, Event:Access, Door:1, Card No.:00015,
2006/12/03 11:05:18, Event:Access, Door:1, Card No.:00016,
2006/12/03 11:05:56, Event:Access, Door:1, Card No.:00015,
2006/12/03 11:05:58, Event:Access, Door:1, Card No.:00016,
2006/12/03 11:06:39, Event:Access, Door:1, Card No.:00015,
2006/12/04 10:53:40, Event:Access, Door:1, Card No.:00011,
2006/12/04 10:53:49, Event:Access, Door:1, Card No.:00010,
2006/12/04 11:01:17, Event:Access, Door:1, Card No.:00010,
2006/12/04 11:01:19, Event:Access, Door:1, Card No.:00011,
2006/12/04 11:03:03, Event:Access, Door:1, Card No.:00012,
2006/12/04 11:03:05, Event:Access, Door:1, Card No.:33333,
2006/12/04 11:03:07, Event:Access, Door:1, Card No.:00123,
2006/12/04 11:03:09, Event:Access, Door:1, Card No.:01234,
2006/12/04 11:04:51, Event:Access, Door:1, Card No.:00015,
2006/12/04 11:05:18, Event:Access, Door:1, Card No.:00016,
2006/12/04 11:05:56, Event:Access, Door:1, Card No.:00015,
2006/12/04 11:05:58, Event:Access, Door:1, Card No.:00016,
2006/12/04 11:06:39, Event:Access, Door:1, Card No.:00015,

it should be separate the file base on there date i.e. 2006/12/01, 2006/12/02, 2006/12/03, 2006/12/04.. then, the file name should be in 12012006, 12022006, 12032006, 12042006...
my code saves them in one file only, that's my main problem...help me please..thanks again..

my code

Dim dwEnrollNumber As Long
    Dim dwVerifyMode As Long
    Dim dwInOutMode As Long
    Dim timeStr As String
    Dim iDate As Date
    Dim i As Long
    Dim FN As Long
    
    FN = FreeFile
    iDate = Date

    dwEnrollNumber = 1
    CZKEM1.ReadAllGLogData 1
        i = i = 1
    'Open "C:\TNA\" & Format(Left(timeStr, 10), "mmddyyyy") & ".txt" For Output As #1
    While CZKEM1.GetGeneralLogDataStr(1, dwEnrollNumber, dwVerifyMode, dwInOutMode, timeStr)
    On Error GoTo Err
    Open "C:\TNA\" & Format(iDate, "mmddyyyy") & ".txt" For Append As #FN
        'i = i + 1
        
        If dwInOutMode = 0 Then
            iInOut = "Event:Access,"
            Else
            iInOut = "Event:Access,"
        End If
        
        Print #1, Format(timeStr, "YYYY/MM/DD HH:MM:SS,") & " " & iInOut & " " & "Door:" & dwVerifyMode & "," & " " & "Card No.:" & Format(dwEnrollNumber, "00000") & ","
        
            i = i + 1
    Wend
    MsgBox "Attendance successfully downloaded"
    Close #FN
    
Err:
    Resume Next

Veena,
thanks, you've solve my 2nd problem, but still my main problem is if i will download all the attendance from the reader it will save only in one file..this is the sample output file... the file name is base on the date i download the file...12052006.txt

it should be separate the file base on there date i.e. 2006/12/01, 2006/12/02, 2006/12/03, 2006/12/04.. then, the file name should be in 12012006, 12022006, 12032006, 12042006...
my code saves them in one file only, that's my main problem...help me please..thanks again..

That's because you use iDate to create the file which holds only the current date. I believe you need timeStr instead. Also, it would be better to break your OPEN statement into two pieces for debugging purposes:

'' First create the file name.  You can then look at it if you need to 
'' before you open the file
fname = "C:\TNA\" & Format(timeStr, "mmddyyyy") & ".txt"

'' Then use that file name to do the actual open
Open fname For Append As #FN

The code is also easier to read this way.

Veena, WaltP
thanks guys, i got the correct output!:cheesy: i just place the Close#FN before the wend

Regards

Veena,
hello my project is almost done! i have two quetions for you how can i output the textfile in a accending order,sample

I have READER A which have this file

2006/12/17 13:22:29, Event:Access, Door:1, Card No.:00001,
2006/12/17 13:22:31, Event:Access, Door:1, Card No.:00002,
2006/12/17 13:22:35, Event:Access, Door:1, Card No.:00003,
2006/12/17 13:22:38, Event:Access, Door:1, Card No.:00001,
2006/12/17 13:22:42, Event:Access, Door:1, Card No.:00002,
2006/12/17 13:22:43, Event:Access, Door:1, Card No.:00001,
2006/12/17 13:22:44, Event:Access, Door:1, Card No.:00002,
2006/12/17 13:22:47, Event:Access, Door:1, Card No.:00001,
2006/12/17 13:22:48, Event:Access, Door:1, Card No.:00002,
2006/12/17 13:22:49, Event:Access, Door:1, Card No.:00001,
2006/12/17 13:22:51, Event:Access, Door:1, Card No.:00002,
2006/12/17 13:22:52, Event:Access, Door:1, Card No.:00001,
2006/12/17 13:22:53, Event:Access, Door:1, Card No.:00002,
2006/12/17 13:22:55, Event:Access, Door:1, Card No.:00001,
2006/12/17 13:22:57, Event:Access, Door:1, Card No.:00002,
2006/12/17 13:22:59, Event:Access, Door:1, Card No.:00001,
2006/12/17 13:23:00, Event:Access, Door:1, Card No.:00002,
2006/12/17 13:23:02, Event:Access, Door:1, Card No.:00001,
2006/12/17 13:23:05, Event:Access, Door:1, Card No.:00002,
2006/12/17 13:23:07, Event:Access, Door:1, Card No.:00001,
2006/12/17 13:23:08, Event:Access, Door:1, Card No.:00002,

And READER B which have this file

2006/12/17 07:16:00, Event:Access, Door:1, Card No.:00001,
2006/12/17 11:52:30, Event:Access, Door:1, Card No.:00002,
2006/12/17 11:52:31, Event:Access, Door:1, Card No.:00001,
2006/12/17 11:52:33, Event:Access, Door:1, Card No.:00002,
2006/12/17 11:52:35, Event:Access, Door:1, Card No.:00003,
2006/12/17 11:52:37, Event:Access, Door:1, Card No.:00004,
2006/12/17 11:52:38, Event:Access, Door:1, Card No.:00001,
2006/12/17 11:52:40, Event:Access, Door:1, Card No.:00002,
2006/12/17 11:52:49, Event:Access, Door:1, Card No.:00004,
2006/12/17 11:52:53, Event:Access, Door:1, Card No.:00003,
2006/12/17 11:53:45, Event:Access, Door:1, Card No.:00001,
2006/12/17 11:53:46, Event:Access, Door:1, Card No.:00001,
2006/12/17 13:21:42, Event:Access, Door:1, Card No.:00001,
2006/12/17 13:21:43, Event:Access, Door:1, Card No.:00002,
2006/12/17 13:21:44, Event:Access, Door:1, Card No.:00003,
2006/12/17 13:21:45, Event:Access, Door:1, Card No.:00001,
2006/12/17 13:21:47, Event:Access, Door:1, Card No.:00004,
2006/12/17 13:22:17, Event:Access, Door:1, Card No.:00001,
2006/12/17 13:22:25, Event:Access, Door:1, Card No.:00001,
2006/12/17 13:22:33, Event:Access, Door:1, Card No.:00001,
2006/12/17 13:22:40, Event:Access, Door:1, Card No.:00001,
2006/12/17 13:22:45, Event:Access, Door:1, Card No.:00001,
2006/12/17 17:00:00, Event:Access, Door:1, Card No.:00001,

Because after reading the Reader A and B the content of Reader B will be place in the end of the file, how can i insert the file in
accending order base on there time..?

my second questions is how can i make the textfile read only, the textfile would not be editable..! is that possible? thanks :p

Hi,

If u have To Display the records, Ordered by Time,
The Simplest way is to Save all the Records in a Temp Table In Database,
Any Database will do .dbf, or .mdb.
Create a table will all the above fields, Save and
Then Query From the TempTable Order By Date/Time.

Any other Coding if u do will take lots of time, to code as well as check.

To make any file Readonly use this code.

SetAttr "C:\MyTextFile.txt", vbReadOnly

Regards
Veena

Open both files 
Open a new file for the merged data
Read a record from each file into Data1 and Data2
Start a loop
    If Data1 < Data2 then
        output Data1
        read a new Data1
    else
        output Data2
        read a new Data2
    endif
    continue with loop

I will let you figure out what to do when you reach the end of a file. That is something you must consider.

hello veena,

can you please help me with this problem, i have a .dat file
the contents is like this
00001 2007-02-12 18:13:13
00001 2007-02-12 18:13:23
00001 2007-02-12 18:13:33
12345 2007-03-12 08:00:09
12345 2007-03-12 09:00:00
00001 2007-04-12 09:08:00
00001 2007-04-12 09:11:00
12345 2007-05-12 08:12:23
00001 2007-05-12 10:11:31

then trying to output the file as text files., split the file base on the date created for their filename i.e. 02122007, 03122007, 04122007, 05122007 see my sample code.. i having a hard time with this one again..thanks in advance

Hi,

Actually, Iam not getting what u want to do here?

Is it that with above data, u want to create 4 different Text files for 4 dates....?


Regards
Veena

yes i want to separate all the text files base on the date...thanks

Hi,

Here I have Changed ur Code and Posted:

Private Sub Command2_Click()
    '
    Dim inFile As Integer
    Dim data() As String
    Dim fields As Integer
    Dim InLine As String
    Dim iDate As String
    Dim NewFile As Long
    Dim NewFileName As String
    '
    inFile = FreeFile
    '***Open "C:\TEXTLOG\1_attlog.dat" For Input As #InFile
    Open App.path & "\1_attlog.dat " For Input As #inFile
     While Not EOF(inFile)
        Line Input #inFile, InLine
        data() = Split(InLine)
        fields = UBound(data())
        iDate = Format(Right(data(0), 10), "MMDDYYYY")
        '
        NewFileName = "C:\Andoks\" & iDate & ".txt"
        NewFile = FreeFile
        Open NewFileName For Append As NewFile
        Print #NewFile, Format(Right(data(0), 10), "YYYY/MM/DD") & " " & Left(data(1), 8) & "," & " " & "Event:Access," & " " & "Door:1," & " " & "Card No.:" & Format(Left(data(0), 5), "00000") & ","
        Close NewFile
        '***Print #1, data(0); vbTab; data(1)
     Wend
    MsgBox "Attendance successfully downloaded ", vbInformation + vbOKOnly, "Record Saved"
    Unload Me
    Me.Show
    Close #inFile
End Sub

I Hope it is clear.

Regards
Veena

Veena,
thanks, you've solve my 2nd problem, but still my main problem is if i will download all the attendance from the reader it will save only in one file..this is the sample output file... the file name is base on the date i download the file...12052006.txt

2006/12/01 10:53:40, Event:Access, Door:1, Card No.:00011,
2006/12/01 10:53:49, Event:Access, Door:1, Card No.:00010,
2006/12/01 11:01:17, Event:Access, Door:1, Card No.:00010,
2006/12/01 11:01:19, Event:Access, Door:1, Card No.:00011,
2006/12/01 11:03:03, Event:Access, Door:1, Card No.:00012,
2006/12/01 11:03:05, Event:Access, Door:1, Card No.:33333,
2006/12/01 11:03:07, Event:Access, Door:1, Card No.:00123,
2006/12/01 11:03:09, Event:Access, Door:1, Card No.:01234,
2006/12/01 11:04:51, Event:Access, Door:1, Card No.:00015,
2006/12/01 11:05:18, Event:Access, Door:1, Card No.:00016,
2006/12/01 11:05:56, Event:Access, Door:1, Card No.:00015,
2006/12/01 11:05:58, Event:Access, Door:1, Card No.:00016,
2006/12/01 11:06:39, Event:Access, Door:1, Card No.:00015,
2006/12/02 10:53:40, Event:Access, Door:1, Card No.:00011,
2006/12/02 10:53:49, Event:Access, Door:1, Card No.:00010,
2006/12/02 11:01:17, Event:Access, Door:1, Card No.:00010,
2006/12/02 11:01:19, Event:Access, Door:1, Card No.:00011,
2006/12/02 11:03:03, Event:Access, Door:1, Card No.:00012,
2006/12/02 11:03:05, Event:Access, Door:1, Card No.:33333,
2006/12/02 11:03:07, Event:Access, Door:1, Card No.:00123,
2006/12/02 11:03:09, Event:Access, Door:1, Card No.:01234,
2006/12/02 11:04:51, Event:Access, Door:1, Card No.:00015,
2006/12/02 11:05:18, Event:Access, Door:1, Card No.:00016,
2006/12/02 11:05:56, Event:Access, Door:1, Card No.:00015,
2006/12/02 11:05:58, Event:Access, Door:1, Card No.:00016,
2006/12/02 11:06:39, Event:Access, Door:1, Card No.:00015,
2006/12/03 10:53:40, Event:Access, Door:1, Card No.:00011,
2006/12/03 10:53:49, Event:Access, Door:1, Card No.:00010,
2006/12/03 11:01:17, Event:Access, Door:1, Card No.:00010,
2006/12/03 11:01:19, Event:Access, Door:1, Card No.:00011,
2006/12/03 11:03:03, Event:Access, Door:1, Card No.:00012,
2006/12/03 11:03:05, Event:Access, Door:1, Card No.:33333,
2006/12/03 11:03:07, Event:Access, Door:1, Card No.:00123,
2006/12/03 11:03:09, Event:Access, Door:1, Card No.:01234,
2006/12/03 11:04:51, Event:Access, Door:1, Card No.:00015,
2006/12/03 11:05:18, Event:Access, Door:1, Card No.:00016,
2006/12/03 11:05:56, Event:Access, Door:1, Card No.:00015,
2006/12/03 11:05:58, Event:Access, Door:1, Card No.:00016,
2006/12/03 11:06:39, Event:Access, Door:1, Card No.:00015,
2006/12/04 10:53:40, Event:Access, Door:1, Card No.:00011,
2006/12/04 10:53:49, Event:Access, Door:1, Card No.:00010,
2006/12/04 11:01:17, Event:Access, Door:1, Card No.:00010,
2006/12/04 11:01:19, Event:Access, Door:1, Card No.:00011,
2006/12/04 11:03:03, Event:Access, Door:1, Card No.:00012,
2006/12/04 11:03:05, Event:Access, Door:1, Card No.:33333,
2006/12/04 11:03:07, Event:Access, Door:1, Card No.:00123,
2006/12/04 11:03:09, Event:Access, Door:1, Card No.:01234,
2006/12/04 11:04:51, Event:Access, Door:1, Card No.:00015,
2006/12/04 11:05:18, Event:Access, Door:1, Card No.:00016,
2006/12/04 11:05:56, Event:Access, Door:1, Card No.:00015,
2006/12/04 11:05:58, Event:Access, Door:1, Card No.:00016,
2006/12/04 11:06:39, Event:Access, Door:1, Card No.:00015,

it should be separate the file base on there date i.e. 2006/12/01, 2006/12/02, 2006/12/03, 2006/12/04.. then, the file name should be in 12012006, 12022006, 12032006, 12042006...
my code saves them in one file only, that's my main problem...help me please..thanks again..

my code

Dim dwEnrollNumber As Long
    Dim dwVerifyMode As Long
    Dim dwInOutMode As Long
    Dim timeStr As String
    Dim iDate As Date
    Dim i As Long
    Dim FN As Long
    
    FN = FreeFile
    iDate = Date

    dwEnrollNumber = 1
    CZKEM1.ReadAllGLogData 1
        i = i = 1
    'Open "C:\TNA\" & Format(Left(timeStr, 10), "mmddyyyy") & ".txt" For Output As #1
    While CZKEM1.GetGeneralLogDataStr(1, dwEnrollNumber, dwVerifyMode, dwInOutMode, timeStr)
    On Error GoTo Err
    Open "C:\TNA\" & Format(iDate, "mmddyyyy") & ".txt" For Append As #FN
        'i = i + 1
        
        If dwInOutMode = 0 Then
            iInOut = "Event:Access,"
            Else
            iInOut = "Event:Access,"
        End If
        
        Print #1, Format(timeStr, "YYYY/MM/DD HH:MM:SS,") & " " & iInOut & " " & "Door:" & dwVerifyMode & "," & " " & "Card No.:" & Format(dwEnrollNumber, "00000") & ","
        
            i = i + 1
    Wend
    MsgBox "Attendance successfully downloaded"
    Close #FN
    
Err:
    Resume Next

Hi see thatb you have used CZKEM1 in ur coding can u tellme if it is a userdefined class or a vb class and how to use it i hv been sent a sdk kitin which this piece of coding is used however it does not work it just says method or datat member not found

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