PaidtheUmpire
Programmer
Here is a question i hope one of you can answer it is a bit difficult to explain but i'll try anyway.
I wish to have a program which, on a single button click, will strip data from files in a given location and place it into a Access 2000 table.
I have broken the problem into five parts
1. Opening the file
2. Reading each line
3. Insertion into an Access 2000 database
4. Looping to do multiple files
5. Closing the files and the database once finished with
PART ONE - OPENING THE FILE
The location which i will be scanning for the files is static : c:\folder\files.dat
The files are all named the same except for a number at the end of the file name:
Qwerty00001.dat,
Qwerty00002.dat ...
Qwerty99999.dat
So i have used the following formula to do that.
CODE:
case FileNumber of
0..9: FileNo := '0000' + IntToStr(FileNumber);
10..99: FileNo := '000' + IntToStr(FileNumber);
100..999: FileNo := '00' + IntToStr(FileNumber);
1000..9999: FileNo := '0' + IntToStr(FileNumber);
else
FileNo := IntToStr(FileNumber);
end;
//So file number is a set 5 character length number 00001 to 99999
//The fileaddress is now going to be:
FileAddress := 'c:\folder\qwerty' + FileNo + '.dat';
//I have the file opening like so:
FileOpen(FileAddress,fmOpenRead);
Is this the best way of opening the said file.
PART TWO - READING EACH LINE
Now that the file is opened i want to be able to read each line in the file and see if the line is filled with needed data. The first two characters tell me if the line is data filled, if the characters are '20' then the line is needed.
If the file is needed then the program will have to strip out sections of the line for use.
SystemNo is the charcters 10 - 24 (length 15)
PhoneNo is the characters 44 - 64 (length 21)
Charge is the characters 128 - 133 (length 6)
Is is possible for the system to read each line and then after seeing if it is needed, extract the correct data.
There maybe more than ONE needed line in each file, but there may also be zero.
My current code doesn't work at all... It gives me the following "EInOutError" and "I/O error 6".
ReadLn(FileAddress, Ch);
PART THREE - INSERTION INTO AN ACCESS 2000 DATABASE
Now that i have gotten the data in the relevant fields (SystemNo, PageNo, Charge), i want to insert the data into an access table located at : 'c:\folder\database.mdb'
The database is passworded with the username/password combo being 'admin'/'q' {A nice easy password huh!}
The table is called ABC_Details and the table fields are SystemNo, PageNo, Charge.
Any ideas how to do this.
PART FOUR - LOOPING TO DO MULTIPLE FILES
At the moment i have the program looping using a While...Do loop
While FileNumber < 1000 do
begin
blah blah
end;
Is this the best way of doing it, or is there an even better way?
PART FIVE - CLOSING THE FILES AND DATABASE ONCE FINISHED WITH
After the program has gone through all of the files that are the folder, i want to close up ALL the opened '.dat' files and the Access Database.
How do you do this?
-----------------
Thankyou all for your help!
I wish to have a program which, on a single button click, will strip data from files in a given location and place it into a Access 2000 table.
I have broken the problem into five parts
1. Opening the file
2. Reading each line
3. Insertion into an Access 2000 database
4. Looping to do multiple files
5. Closing the files and the database once finished with
PART ONE - OPENING THE FILE
The location which i will be scanning for the files is static : c:\folder\files.dat
The files are all named the same except for a number at the end of the file name:
Qwerty00001.dat,
Qwerty00002.dat ...
Qwerty99999.dat
So i have used the following formula to do that.
CODE:
case FileNumber of
0..9: FileNo := '0000' + IntToStr(FileNumber);
10..99: FileNo := '000' + IntToStr(FileNumber);
100..999: FileNo := '00' + IntToStr(FileNumber);
1000..9999: FileNo := '0' + IntToStr(FileNumber);
else
FileNo := IntToStr(FileNumber);
end;
//So file number is a set 5 character length number 00001 to 99999
//The fileaddress is now going to be:
FileAddress := 'c:\folder\qwerty' + FileNo + '.dat';
//I have the file opening like so:
FileOpen(FileAddress,fmOpenRead);
Is this the best way of opening the said file.
PART TWO - READING EACH LINE
Now that the file is opened i want to be able to read each line in the file and see if the line is filled with needed data. The first two characters tell me if the line is data filled, if the characters are '20' then the line is needed.
If the file is needed then the program will have to strip out sections of the line for use.
SystemNo is the charcters 10 - 24 (length 15)
PhoneNo is the characters 44 - 64 (length 21)
Charge is the characters 128 - 133 (length 6)
Is is possible for the system to read each line and then after seeing if it is needed, extract the correct data.
There maybe more than ONE needed line in each file, but there may also be zero.
My current code doesn't work at all... It gives me the following "EInOutError" and "I/O error 6".
ReadLn(FileAddress, Ch);
PART THREE - INSERTION INTO AN ACCESS 2000 DATABASE
Now that i have gotten the data in the relevant fields (SystemNo, PageNo, Charge), i want to insert the data into an access table located at : 'c:\folder\database.mdb'
The database is passworded with the username/password combo being 'admin'/'q' {A nice easy password huh!}
The table is called ABC_Details and the table fields are SystemNo, PageNo, Charge.
Any ideas how to do this.
PART FOUR - LOOPING TO DO MULTIPLE FILES
At the moment i have the program looping using a While...Do loop
While FileNumber < 1000 do
begin
blah blah
end;
Is this the best way of doing it, or is there an even better way?
PART FIVE - CLOSING THE FILES AND DATABASE ONCE FINISHED WITH
After the program has gone through all of the files that are the folder, i want to close up ALL the opened '.dat' files and the Access Database.
How do you do this?
-----------------
Thankyou all for your help!