| | |
how to validate text file, loading into listbox
Thread Solved |
•
•
Join Date: Sep 2006
Posts: 54
Reputation:
Solved Threads: 1
2005/11/09 18:32:11, Event:Access, Door:entry, Card No.:2727, Description:266:55748
Date time event door card no. description
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2005/11/09 18:32:11, Event:Access, Door:entry, Card No.:2727, Description:266:55748
2005/11/09 18:32:13, Event:Access, Door:entry, Card No.:2345, Description:266:55732
2006/01/11 14:07:02, Event:Cover Removed Return to Normal, Door:5
2006/01/11 14:07:02, Event:Cover Removed Alarm, Door:5
2005/11/09 18:33:58, Event:Card No. Error, Door:entry, Description:266:51792
2006/01/11 14:07:02, Event:Cover Removed Return to Normal, Door:5
2006/01/24 17:31:27, Eventownload Success!
2006/01/11 14:07:02, Event:Cover Removed Alarm, Door:5
2005/11/09 18:32:21, Event:Access, Door:entry, Card No.:2727, Description:266:55748
2006/01/24 17:31:27, Eventownload Success!
2005/11/09 18:33:58, Event:Card No. Error, Door:entry, Description:266:51792
2006/01/11 14:07:02, Event:Cover Removed Return to Normal, Door:5
2006/01/11 14:07:02, Event:Cover Removed Alarm, Door:5
2005/11/09 18:34:00, Event:Card No. Error, Door:entry, Description:266:51792
2006/01/24 17:31:27, Eventownload Success!
2005/11/09 18:33:20, Event:Card No. Error, Door:entry, Description:266:51792
2005/11/09 18:32:36, Event:Access, Door:entry, Card No.:2727, Description:266:55748
2005/11/09 18:32:46, Event:Access, Door:entry, Card No.:2727, Description:266:55748
2005/11/09 18:32:54, Event:Card No. Error, Door:entry, Description:266:51792
2005/11/09 18:33:42, Event:Card No. Error, Door:entry, Description:266:51792
2005/11/09 18:34:36, Event:Card No. Error, Door:entry, Description:266:51792
hello everyone... can you please help me with my problem, i have a project time and attendance system using a reader which the reader creates a textlog. want i want to do is to save only the row that have a format above, and those row that mismatch the format discard it.. i already know how to save it in database, i just want to validate the saving..hope you can help me
Dim inFile As Integer
Dim InLine As String
Dim data() As String
Dim fields As Integer
Dim sFile As String
sFile = txtFile.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
data() = Split(InLine)
fields = UBound(data())
On Error GoTo badfile
conn.Execute "INSERT INTO tblattendance (Date, TimeIn, Event, CardNumber, Description) " & _
"VALUES ('" & data(0) & "', " & _
"' " & Left(data(1), 8) & "', " & _
"' " & Mid(data(2), 7) & "', " & _
"' " & Card(data(5)) & "', " & _
"' " & data(6) & "')"
Wend
MsgBox "Record successfully saved ", vbInformation + vbOKOnly, "Record Saved"
Unload Me
Me.Show
Close #inFile
Exit Sub
badfile:
MsgBox "Error type of file ", vbCritical + vbOKOnly, "Error"
or if somebody help me on how to load the textfile in listbox, same validation ingnore the data that not match the format above....
========================code to open the textfile in list box, just help to validate the format above=======================
Dim sFile As String
Dim inFile As Integer
Dim sTemp As String
Open sFile For Input As inFile
While Not EOF(inFile)
Line Input #inFile, sTemp
olist.AddItem sTemp
Wend
Close inFile
Date time event door card no. description
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2005/11/09 18:32:11, Event:Access, Door:entry, Card No.:2727, Description:266:55748
2005/11/09 18:32:13, Event:Access, Door:entry, Card No.:2345, Description:266:55732
2006/01/11 14:07:02, Event:Cover Removed Return to Normal, Door:5
2006/01/11 14:07:02, Event:Cover Removed Alarm, Door:5
2005/11/09 18:33:58, Event:Card No. Error, Door:entry, Description:266:51792
2006/01/11 14:07:02, Event:Cover Removed Return to Normal, Door:5
2006/01/24 17:31:27, Eventownload Success!
2006/01/11 14:07:02, Event:Cover Removed Alarm, Door:5
2005/11/09 18:32:21, Event:Access, Door:entry, Card No.:2727, Description:266:55748
2006/01/24 17:31:27, Eventownload Success!
2005/11/09 18:33:58, Event:Card No. Error, Door:entry, Description:266:51792
2006/01/11 14:07:02, Event:Cover Removed Return to Normal, Door:5
2006/01/11 14:07:02, Event:Cover Removed Alarm, Door:5
2005/11/09 18:34:00, Event:Card No. Error, Door:entry, Description:266:51792
2006/01/24 17:31:27, Eventownload Success!
2005/11/09 18:33:20, Event:Card No. Error, Door:entry, Description:266:51792
2005/11/09 18:32:36, Event:Access, Door:entry, Card No.:2727, Description:266:55748
2005/11/09 18:32:46, Event:Access, Door:entry, Card No.:2727, Description:266:55748
2005/11/09 18:32:54, Event:Card No. Error, Door:entry, Description:266:51792
2005/11/09 18:33:42, Event:Card No. Error, Door:entry, Description:266:51792
2005/11/09 18:34:36, Event:Card No. Error, Door:entry, Description:266:51792
hello everyone... can you please help me with my problem, i have a project time and attendance system using a reader which the reader creates a textlog. want i want to do is to save only the row that have a format above, and those row that mismatch the format discard it.. i already know how to save it in database, i just want to validate the saving..hope you can help me
Dim inFile As Integer
Dim InLine As String
Dim data() As String
Dim fields As Integer
Dim sFile As String
sFile = txtFile.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
data() = Split(InLine)
fields = UBound(data())
On Error GoTo badfile
conn.Execute "INSERT INTO tblattendance (Date, TimeIn, Event, CardNumber, Description) " & _
"VALUES ('" & data(0) & "', " & _
"' " & Left(data(1), 8) & "', " & _
"' " & Mid(data(2), 7) & "', " & _
"' " & Card(data(5)) & "', " & _
"' " & data(6) & "')"
Wend
MsgBox "Record successfully saved ", vbInformation + vbOKOnly, "Record Saved"
Unload Me
Me.Show
Close #inFile
Exit Sub
badfile:
MsgBox "Error type of file ", vbCritical + vbOKOnly, "Error"
or if somebody help me on how to load the textfile in listbox, same validation ingnore the data that not match the format above....
========================code to open the textfile in list box, just help to validate the format above=======================
Dim sFile As String
Dim inFile As Integer
Dim sTemp As String
Open sFile For Input As inFile
While Not EOF(inFile)
Line Input #inFile, sTemp
olist.AddItem sTemp
Wend
Close inFile
•
•
Join Date: Nov 2005
Posts: 134
Reputation:
Solved Threads: 10
royaloba,
In order to parse out the data you do not want I suggest validating the input line before splitting it into the data() array.
Assuming that you only want the "Access" events in your database I would change your code to the following:
You should now be able to change the condition to include whatever events you want, i.e. "Card No. Error" or others, by simply adding conditions to the "If ... Then" statement.
Similarly you can screen out certain doors by using the same technique,
i.e.
Hope this helps
Yomet
In order to parse out the data you do not want I suggest validating the input line before splitting it into the data() array.
Assuming that you only want the "Access" events in your database I would change your code to the following:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
While Not EOF(inFile) Line Input #inFile, InLine If InStr(InLine, "Event:Access") > 0 Then Data() = Split(InLine) Fields = UBound(Data()) On Error GoTo badfile conn.Execute "INSERT INTO tblattendance (Date, TimeIn, Event, CardNumber, Description) " & _ "VALUES ('" & Data(0) & "', " & _ "' " & Left(Data(1), 8) & "', " & _ "' " & Mid(Data(2), 7) & "', " & _ "' " & Card(Data(5)) & "', " & _ "' " & Data(6) & "')" End If Wend
You should now be able to change the condition to include whatever events you want, i.e. "Card No. Error" or others, by simply adding conditions to the "If ... Then" statement.
Similarly you can screen out certain doors by using the same technique,
i.e.
If InStr(InLine, "Door:entry") > 0 ThenHope this helps
Yomet
•
•
Join Date: Nov 2005
Posts: 134
Reputation:
Solved Threads: 10
•
•
•
•
Originally Posted by royaloba in PM
hello sir it's me again.... i finish the validation on saving the textlog... i'm adding a new
field in the Table Its TimeOut here's the senario sir i want to put the first time in fields
TIMEIN, Then last record will be for TIMEOUT..base on their card number! did you get me sir??
i already try it sir, but the problem when i save it, the output is like this...
Date TimeIn Event Door CardNumber TimeOut
2005/11/24 09:32:42, Access, Door:entry, 2727 9:33:30
2005/11/24 09:33:30, Access, Door:entry, 2727
2005/11/24 09:33:42, Access, Door:entry, 2727
2005/11/24 09:34:04, Access, Door:entry, 2727
2005/11/24 09:42:05, Access, Door:entry, 2727
2005/11/24 09:51:13, Access, Door:entry, 2345
2005/11/24 09:51:19, Access, Door:entry, 2345
2005/11/24 09:51:26, Access, Door:entry, 2345
2005/11/24 09:51:37, Access, Door:entry, 2345
2005/11/24 09:51:47, Access, Door:entry, 2345
2005/11/24 09:55:25, Access, Door:entry, 2727
2005/11/24 16:30:50, Access, Door:entry, 2345
this is the output i want sir
Date TimeIn Event Door CardNumber TimeOut
2005/11/24 09:33:42 Access, Door:entry, 2727 9:55:25
2005/11/24 09:51:19 Acesss, Door:entry, 2345 16:30:50
i want to save only the first swipe of the card(first us timein) and the last swipe of the
card(last us TimetOut). i keep on asking if it is possible, cause i'm in stage of getting
familiar with vb not in the stage of a senior or junior programmer... i hope you can help me
sir..
or if you have a other way to do it sir...by the way again thanks to the previous code you gave
me..it's working well sir..
As I said in my answer to your PM I am posting your question and my answer here for everybody to profit from the information exchanged.
Without giving you the code I will give you the steps I would take to do this.
1) Every time you read a log line you need to see if that card has already been used during that day
HINT use a SELECT statement with date and card number in the WHERE clause
2) If the card has not been used then you need to add an entry into your table with the card number, date and time as Time In - this is the code you already have.
3) If the card has already been used you need to update the table with the current time as Time Out - this is the code you need to create
HINT use an UPDATE statement
Hope this helps and please tell me how it works out
Yomet
•
•
Join Date: Nov 2005
Posts: 134
Reputation:
Solved Threads: 10
Hi again royaloba,
When I said a SELECT statement I did not mean a SELECT CASE statement but rather a SQL SELECT statement.
Here is the gist of what I would do, this might not work correctly in your program but with minor tweaks it should.
Hope this code sheds some light on the solution to your problem.
Happy coding
Yomet
When I said a SELECT statement I did not mean a SELECT CASE statement but rather a SQL SELECT statement.
Here is the gist of what I would do, this might not work correctly in your program but with minor tweaks it should.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
'You will need to add the following declaration Dim rs As Recordset
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
While Not EOF(inFile) Line Input #inFile, InLine If InStr(InLine, "Event:Access") > 0 Then Data() = Split(InLine) Fields = UBound(Data()) On Error GoTo badfile Set rs = CurrentDb.OpenRecordset("SELECT * FROM tblattendance WHERE [Date] = '" & Data(0) & "' AND CardNumber = '" & Data(5) & "'") If rs.EOF Then 'No data returned, i.e. first time this card is used conn.Execute "INSERT INTO tblattendance (Date, TimeIn, Event, CardNumber, Description) " & _ "VALUES ('" & Data(0) & "', " & _ "' " & Left(Data(1), 8) & "', " & _ "' " & Mid(Data(2), 7) & "', " & _ "' " & Card(Data(5)) & "', " & _ "' " & Data(6) & "')" Else 'Data has been returned, i.e. the card has already been used today conn.Execute "UPDATE tblattendance SET TimeOut = '" & Left(Data(1), 8 & "'") End If rs.Close Set rs = Nothing End If Wend
Hope this code sheds some light on the solution to your problem.
Happy coding
Yomet
•
•
Join Date: Sep 2006
Posts: 54
Reputation:
Solved Threads: 1
hello sir jomet its me again.. still i can't solve my problem before.. please help. this is regarding with the timein timeout issue that i tell you before i include the program so you could tell where the problem is..please help me..i will also include the mysql database
username=admin
pasword=admin
username=admin
pasword=admin
•
•
Join Date: Nov 2005
Posts: 134
Reputation:
Solved Threads: 10
Hi royaloba,
Sorry to hear that things are not working out. I would like to know what is going wrong. Just saying "It's not working" does not help me a lot since there are a million things that could be not working. For instance, I found a syntax error in your UPDATE statement, you coded "UPDATE INTO" whereas the correct syntax is so if your error is a syntax error that might be your problem.
I made an error, that you corrected nicely, by assuming you were using an Access database, thanks for not getting me into trouble...
I do not have MySQL installed on my computer so I cannot run your program, it gives me an error about the ODBC data source not being defined etc.
If you could give me a better description of what is going wrong it would be very helpful.
Thanks
Yomet
P.S. My nick is spelled with "Y" not "J"...
Sorry to hear that things are not working out. I would like to know what is going wrong. Just saying "It's not working" does not help me a lot since there are a million things that could be not working. For instance, I found a syntax error in your UPDATE statement, you coded "UPDATE INTO" whereas the correct syntax is
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
UPDATE <tablename> SET <field> = <value>[, <field> = <value>[,...]] [WHERE <where clause>]
I made an error, that you corrected nicely, by assuming you were using an Access database, thanks for not getting me into trouble...

I do not have MySQL installed on my computer so I cannot run your program, it gives me an error about the ODBC data source not being defined etc.
If you could give me a better description of what is going wrong it would be very helpful.
Thanks
Yomet
P.S. My nick is spelled with "Y" not "J"...
•
•
Join Date: Sep 2006
Posts: 54
Reputation:
Solved Threads: 1
Code:
---------
'You will need to add the following declaration
Dim rs As Recordset
---------
Code:
---------
While Not EOF(inFile)
Line Input #inFile, InLine
If InStr(InLine, "Event:Access") > 0 Then
Data() = Split(InLine)
Fields = UBound(Data())
On Error GoTo badfile
Set rs = CurrentDb.OpenRecordset("SELECT * FROM tblattendance
WHERE [Date] = '" & Data(0) & "' AND CardNumber = '" & Data(5) & "'")
If rs.EOF Then 'No data returned, i.e. first time this card is
used
conn.Execute "INSERT INTO tblattendance (Date, TimeIn, Event,
CardNumber, Description) " & _
"VALUES ('" & Data(0) & "', " & _
"' " & Left(Data(1), 8) & "', " & _
"' " & Mid(Data(2), 7) & "', " & _
"' " & Card(Data(5)) & "', " & _
"' " & Data(6) & "')"
Else 'Data has been returned, i.e. the card has already been
used today
conn.Execute "UPDATE tblattendance SET TimeOut = '" &
Left(Data(1), 8 & "'")
End If
rs.Close
Set rs = Nothing
End If
Wend
---------
sir YOMET,
hello sir that is the sample code that you given to me, before...my problem is the set rs=currentdb.OpenRecordset is not working with mysql database. i just modify your code into
While Not EOF(inFile)
Line Input #inFile, InLine
If InStr(InLine, "Event:Access") > 0 Then
data() = Split(InLine)
fields = UBound(data())
'On Error GoTo badfile
Set rs = New ADODB.Recordset
squery = "": squery = ("Select * from tblattendance where Date='" & data(0) & "' AND CardNumber = '" & data(5) & "'")
Call ExecuteCommand
If rs.EOF Then ' NO DATA RETURNED
conn.Execute "INSERT INTO tblattendance (Date, TimeIn, Event, CardNumber) " & _
"VALUES ('" & data(0) & "', " & _
"'" & Left(data(1), 8) & "', " & _
"'" & Mid(data(2), 7) & "', " & _
"'" & Card(data(5)) & "')"
Else ' DATA HAS BEEN USED
conn.Execute "UPDATE tblattendance set TimeOut='" & Left(data(1), 8 & "'")
End If
rs.Close
Set rs = Nothing
End If
but still the output is the same... see the sample pic that i attach...
---------
'You will need to add the following declaration
Dim rs As Recordset
---------
Code:
---------
While Not EOF(inFile)
Line Input #inFile, InLine
If InStr(InLine, "Event:Access") > 0 Then
Data() = Split(InLine)
Fields = UBound(Data())
On Error GoTo badfile
Set rs = CurrentDb.OpenRecordset("SELECT * FROM tblattendance
WHERE [Date] = '" & Data(0) & "' AND CardNumber = '" & Data(5) & "'")
If rs.EOF Then 'No data returned, i.e. first time this card is
used
conn.Execute "INSERT INTO tblattendance (Date, TimeIn, Event,
CardNumber, Description) " & _
"VALUES ('" & Data(0) & "', " & _
"' " & Left(Data(1), 8) & "', " & _
"' " & Mid(Data(2), 7) & "', " & _
"' " & Card(Data(5)) & "', " & _
"' " & Data(6) & "')"
Else 'Data has been returned, i.e. the card has already been
used today
conn.Execute "UPDATE tblattendance SET TimeOut = '" &
Left(Data(1), 8 & "'")
End If
rs.Close
Set rs = Nothing
End If
Wend
---------
sir YOMET,
hello sir that is the sample code that you given to me, before...my problem is the set rs=currentdb.OpenRecordset is not working with mysql database. i just modify your code into
While Not EOF(inFile)
Line Input #inFile, InLine
If InStr(InLine, "Event:Access") > 0 Then
data() = Split(InLine)
fields = UBound(data())
'On Error GoTo badfile
Set rs = New ADODB.Recordset
squery = "": squery = ("Select * from tblattendance where Date='" & data(0) & "' AND CardNumber = '" & data(5) & "'")
Call ExecuteCommand
If rs.EOF Then ' NO DATA RETURNED
conn.Execute "INSERT INTO tblattendance (Date, TimeIn, Event, CardNumber) " & _
"VALUES ('" & data(0) & "', " & _
"'" & Left(data(1), 8) & "', " & _
"'" & Mid(data(2), 7) & "', " & _
"'" & Card(data(5)) & "')"
Else ' DATA HAS BEEN USED
conn.Execute "UPDATE tblattendance set TimeOut='" & Left(data(1), 8 & "'")
End If
rs.Close
Set rs = Nothing
End If
but still the output is the same... see the sample pic that i attach...
![]() |
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.
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college 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 listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows






