| | |
how to validate text file, loading into listbox
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Sep 2006
Posts: 54
Reputation:
Solved Threads: 1
sir yomet
hello sir i have some good news for you, i was able to set the TIMEOUT, but there is few error i want to fix..
SAMPLE OUTPUT mysql
--------------------------------------------------------------------------------
Date TimeIn Event CardNumber TimeOut
--------------------------------------------------------------------------------
2002-05-02 | 21:30:12 | Access | 451 | 21:32:09 |
2002-05-02 | 21:30:12 | Access | 451 | 21:32:09 |
2002-05-02 | 21:30:22 | Access | 451 | 21:32:09 |
2002-05-02 | 21:30:48 | Access | 546 | 21:32:09 |
2002-05-02 | 21:30:55 | Access | 546 | 21:32:09 |
2002-05-02 | 21:31:19 | Access | 546 | 21:32:09 |
2002-05-02 | 21:31:59 | Access | 234 | 21:32:09 |
2002-05-02 | 21:32:06 | Access | 234 | 21:32:09 |
2002-05-02 | 21:32:08 | Access | 234 | 21:32:09 |
2002-05-02 | 21:32:09 | Access | 234 | 21:32:09 |
---------------------------------------------------------------------------------
i just revise some of your sample code sir... as you see in the output i
the code read only the last TimeIn... the right output shoul be like this
--------------------------------------------------------------------------------
Date TimeIn Event CardNumber TimeOut
--------------------------------------------------------------------------------
2002-05-02 | 21:30:12 | Access | 451 | 21:32:22 |
2002-05-02 | 21:30:48 | Access | 546 | 21:31:19 |
2002-05-02 | 21:31:59 | Access | 234 | 21:32:09 |
--------------------------------------------------------------------------------
read only the first TimeIn and the LAST record and put this as TimeOut Base on their CARDNUMBER and the DATE...i need your suggestions sir...thanks..and if you can provide me a bit of code...thanks
THE CODE I USE SIR
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())
conn.Execute "INSERT INTO tblattendance (Date, TimeIn, Event, CardNumber) " & _
"VALUES ('" & data(0) & "', " & _
"'" & Left(data(1), 8) & "', " & _
"'" & Mid(data(2), 7) & "', " & _
"'" & Card(data(5)) & "')"
Set rs = New ADODB.Recordset
squery = "": squery = "Select * from tblattendance where Date='" & data(0) & "' and CardNumber='" & data(5) & "'"
Call ExecuteCommand
If rs.EOF Then ' DATA HAS BEEN USED
conn.Execute "UPDATE tblattendance set TimeOut = '" & Left(data(1), 8) & "'"
End If
rs.Close
Set rs = Nothing
End If
hello sir i have some good news for you, i was able to set the TIMEOUT, but there is few error i want to fix..
SAMPLE OUTPUT mysql
--------------------------------------------------------------------------------
Date TimeIn Event CardNumber TimeOut
--------------------------------------------------------------------------------
2002-05-02 | 21:30:12 | Access | 451 | 21:32:09 |
2002-05-02 | 21:30:12 | Access | 451 | 21:32:09 |
2002-05-02 | 21:30:22 | Access | 451 | 21:32:09 |
2002-05-02 | 21:30:48 | Access | 546 | 21:32:09 |
2002-05-02 | 21:30:55 | Access | 546 | 21:32:09 |
2002-05-02 | 21:31:19 | Access | 546 | 21:32:09 |
2002-05-02 | 21:31:59 | Access | 234 | 21:32:09 |
2002-05-02 | 21:32:06 | Access | 234 | 21:32:09 |
2002-05-02 | 21:32:08 | Access | 234 | 21:32:09 |
2002-05-02 | 21:32:09 | Access | 234 | 21:32:09 |
---------------------------------------------------------------------------------
i just revise some of your sample code sir... as you see in the output i
the code read only the last TimeIn... the right output shoul be like this
--------------------------------------------------------------------------------
Date TimeIn Event CardNumber TimeOut
--------------------------------------------------------------------------------
2002-05-02 | 21:30:12 | Access | 451 | 21:32:22 |
2002-05-02 | 21:30:48 | Access | 546 | 21:31:19 |
2002-05-02 | 21:31:59 | Access | 234 | 21:32:09 |
--------------------------------------------------------------------------------
read only the first TimeIn and the LAST record and put this as TimeOut Base on their CARDNUMBER and the DATE...i need your suggestions sir...thanks..and if you can provide me a bit of code...thanks
THE CODE I USE SIR
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())
conn.Execute "INSERT INTO tblattendance (Date, TimeIn, Event, CardNumber) " & _
"VALUES ('" & data(0) & "', " & _
"'" & Left(data(1), 8) & "', " & _
"'" & Mid(data(2), 7) & "', " & _
"'" & Card(data(5)) & "')"
Set rs = New ADODB.Recordset
squery = "": squery = "Select * from tblattendance where Date='" & data(0) & "' and CardNumber='" & data(5) & "'"
Call ExecuteCommand
If rs.EOF Then ' DATA HAS BEEN USED
conn.Execute "UPDATE tblattendance set TimeOut = '" & Left(data(1), 8) & "'"
End If
rs.Close
Set rs = Nothing
End If
•
•
Join Date: Nov 2005
Posts: 134
Reputation:
Solved Threads: 10
royaloba,
I can see where you code is going wrong and there are two quite simple errors.
1) What you do is adding a record every time you read a line wihtout first verifying if that card has already been used today.
2) The UPDATE statement later on will update all the records - not only the ones for that specific card and day. This error comes from my own code so I take full responsibility for it, I forgot to add the WHERE clause in the code I gave you.
Using your own code I will show you what I am talking about and how to correct it.
BTW, please use the code tags like this
[ code ]
Here goes all your code.
Please remove the spaces between the square brackets "[" and "]" and the "code" and "/code" parts
[ /code ]
OK, here goes
Seeing my last answer I would like to say sorry for misleading you, I was tired and didn't read the code correctly, there was no syntax error, just my eyes seeing double... :o
As far as I can see this should do the trick. Try it out and tell me how it works.
Happy coding
Yomet
I can see where you code is going wrong and there are two quite simple errors.
1) What you do is adding a record every time you read a line wihtout first verifying if that card has already been used today.
2) The UPDATE statement later on will update all the records - not only the ones for that specific card and day. This error comes from my own code so I take full responsibility for it, I forgot to add the WHERE clause in the code I gave you.
Using your own code I will show you what I am talking about and how to correct it.
BTW, please use the code tags like this
[ code ]
Here goes all your code.
Please remove the spaces between the square brackets "[" and "]" and the "code" and "/code" parts
[ /code ]
OK, here goes
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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()) '********************** 'At this point you have fresh data in your array and what you 'WANT to do is verify if the current card, in Card(data(5)), has 'already been used today. 'What you need here is a condition to see if the card has already 'been used. Actually the IF statement you use later is almost there, i.e. Set rs = New ADODB.Recordset squery = "": squery = "Select * from tblattendance where Date='" & data(0) & "' and CardNumber='" & data(5) & "'" Call ExecuteCommand 'If rs.EOF Then ' DATA HAS BEEN USED If NOT rs.EOF Then 'Data has NOT been used so insert it. '********************** conn.Execute "INSERT INTO tblattendance (Date, TimeIn, Event, CardNumber) " & _ "VALUES ('" & data(0) & "', " & _ "'" & Left(data(1), 8) & "', " & _ "'" & Mid(data(2), 7) & "', " & _ "'" & Card(data(5)) & "')" '********************** 'Now you have inserted the data into your database since it was 'not there to begin with. 'However, if the data was already in the table you need to update 'the TimeOut with the current time. So we scrap the If statement '(since we used it above) and use the else clause. Else '********************** 'Set rs = New ADODB.Recordset 'squery = "": squery = "Select * from tblattendance where Date='" & 'data(0) & "' and CardNumber='" & data(5) & "'" 'Call ExecuteCommand 'If rs.EOF Then ' DATA HAS BEEN USED 'conn.Execute "UPDATE tblattendance set TimeOut = '" & Left(data(1), 8) & "'" '********************** 'The new UPDATE statement conn.Execute "UPDATE tblattendance set TimeOut = '" & Left(data(1), 8) & "'" & _ WHERE Date='" & 'data(0) & "' and CardNumber='" & data(5) & "'" '********************** End If rs.Close Set rs = Nothing End If
Seeing my last answer I would like to say sorry for misleading you, I was tired and didn't read the code correctly, there was no syntax error, just my eyes seeing double... :o
As far as I can see this should do the trick. Try it out and tell me how it works.
Happy coding
Yomet
•
•
Join Date: Sep 2006
Posts: 54
Reputation:
Solved Threads: 1
hello sir Yomet
first thanks for helping me with this project
the problem is when i put the "if not rs.eof then" the return record in the data base in empty... and when i replace it with "if rs.eof" the ouput for all the timeout is the same..sir i attach a sample program, i convert it to access so you could determine where is the problem occurs..thanks sir..
first thanks for helping me with this project
the problem is when i put the "if not rs.eof then" the return record in the data base in empty... and when i replace it with "if rs.eof" the ouput for all the timeout is the same..sir i attach a sample program, i convert it to access so you could determine where is the problem occurs..thanks sir..
•
•
Join Date: Nov 2005
Posts: 134
Reputation:
Solved Threads: 10
royaloba,
Thanks for taking the time to convert your database into Access, it helped.
Now for what I found:
1) There seems to be some problem with the "ExecuteCommand" sub since it never gives back a recordset with records in it. However when I replaced that line with
2) I had to revert to your original code for inserting and updating records by using
You were correct in using
Hope this code works and keep up the good work.
Yomet
Thanks for taking the time to convert your database into Access, it helped.
Now for what I found:
1) There seems to be some problem with the "ExecuteCommand" sub since it never gives back a recordset with records in it. However when I replaced that line with
rs.Open squery, conn it gave the expected results.2) I had to revert to your original code for inserting and updating records by using
conn.Execute instead of db.Execute because when using the mix between DAO and ADODB the record was not saved by DAO before the ADODB went to find it. Weird I know but by using the following code everything went well. Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Open sFile For Input As #inFile ' Set db = DBEngine.OpenDatabase(App.Path & "\db1.mdb") 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)) & "'" ' Call ExecuteCommand rs.Open squery, conn If rs.EOF Then conn.Execute "INSERT INTO tblattendance ([Date], [TimeIn], CardNumber) " & _ "VALUES (#" & data(0) & "#, " & _ "'" & Left(data(1), 8) & "', " & _ "'" & Card(data(5)) & "')" 'Set rs = New ADODB.Recordset 'squery = "": squery = "Select * from tblattendance where Date='" & data(0) & "' and CardNumber='" & data(5) & "'" 'Call ExecuteCommand 'If rs.EOF Then ' DATA HAS BEEN USED Else conn.Execute "UPDATE tblattendance set TimeOut = '" & Left(data(1), 8) & "' 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 Close #inFile Exit Sub
You were correct in using
If rs.EOF instead of If Not rs.EOF, typical brain-fart on my behalf.Hope this code works and keep up the good work.
Yomet
![]() |
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Microsoft OLEDB Chart Control Version 6 question
- Next Thread: Sorting has me out of sorts.
Views: 8384 | Replies: 15
| Thread Tools | Search this Thread |
Tag cloud for Visual Basic 4 / 5 / 6
* 6 2007 access activex add age append application basic beginner birth bmp c++ calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver struct subroutine table tags textbox time timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





