Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error in code?

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
With all the tips and help I've found I've developed the following procedure. It allows the user to select the file to upload and then should look at each line and extract the needed information. When I run the code, the Open File Dialog box opens, I select my file, but when it gets to the "While Not EOF Do" I get an I/O error. When I use the debugger, I find that my file is still NOTHING!

procedure TfrmMainMenu.UploadVenire1Click(Sender: TObject);
var
F: TextFile;
S: string;
FullName, LastName, FirstName, Address, City, State, Zip, TermDate: string;
begin
if OpenDialog1.Execute then { Display Open dialog box }
begin
AssignFile(F, OpenDialog1.FileName); { File selected in dialog }
Reset(F);
While Not EOF do
begin
Readln(F, S); { Read first line of file }
FullName := Copy(S, 160,30); // extract name
Address := copy(S,190,25); // extract address
City := copy(S, 215,15); //extract city
State := copy(S, 230, 2);
Zip := copy(S, 232,9);
TermDate := copy(S, 16,6);
end;
CloseFile(F);
end;
end;

Thanks for any input!

Leslie
 
I did a quick visual check of your code and noticed an error in your syntax. EOF should be EOF(F).

I did not know that it could compile with out the arguement to EOF.
 
Les I would simply use tsringlist and avoid all complications.
var sl:tstringlist;i:integer;


sl:=tstringlist.create;
sl.loadfromfile(opendialog1.filename);
for i:=0 to sl.count-1 do
begin
s:=sl;
FullName := Copy(S, 160,30); // extract name
Address := copy(S,190,25); // extract address
.....
......//remaining code
end;

sl.free;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top