| | |
How to open multiple textfile
![]() |
•
•
Join Date: Sep 2006
Posts: 54
Reputation:
Solved Threads: 1
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
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
•
•
Join Date: Nov 2005
Posts: 134
Reputation:
Solved Threads: 10
•
•
•
•
Originally Posted by royaloba in PM
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
-----------------------------------------------------------Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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..
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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
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: Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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
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
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
•
•
Join Date: Sep 2006
Posts: 54
Reputation:
Solved Threads: 1
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
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,
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
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
![]() |
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: i need help
- Next Thread: Editing Msgbox in visualbasic 6
| Thread Tools | Search this Thread |
* 6 2007 access activex add age basic birth bmp calculator cd cells.find click client code connection connectionproblemusingvb6usingoledb creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit excel excelmacro file filename form header iamthwee image inboxinvb internetfiledownload listbox listview liveperson login looping microsoft movingranges objectinsert open oracle password program prompt range-objects readfile reading remotesqlserverdatabase report save search sendbyte sites sql sql2008 sqlserver subroutine tags time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web windows





