Board index » delphi » End of file use with tab delimited text file

End of file use with tab delimited text file

Hello,

The following program works great for me if my 'txtFile' has the following
form

1
2
3
4
5
6

However, I need my program to read the first number from a 'txtFile' that
has the following form

1 10
2 20
3 30
4 40
5 50
6 60

Could anyone suggest a way that I can change my program (listed below) to do
this?

Thank you in advance
Jamie

var
txtFile: System.Text;
txtwrite: System.Text;
filePath: String;
filewrite: String;
Num : integer;
begin
filePath := 'c:\BCv6_2_3\datainput\Run Number.in';
filewrite := 'c:\BCv6_2_3\datainput\write.in';

AssignFile(txtFile, filePath);
ReSet(txtFile);
AssignFile(txtwrite, filewrite);
Rewrite(txtwrite);

while not Eof(txtFile) do
begin
Readln(txtFile, Num);
if Num>0 then begin
writeln(txtwrite, Num);

Edit1.text:= IntToStr(Num);
end;
end;
System.Close(txtFile);
System.Close(txtwrite);
end;

 

Re:End of file use with tab delimited text file


the 'txtFile' if Run Number.csv

sorry for any inconvinence

Jamie

Re:End of file use with tab delimited text file


Hi,

I had to use Readln to input a line of comma-delimited data and then create
a loop to extract individual values.  It's not simple, but it was the only
way I found.

"Name","Address","Phone" //read whole line then use something like POS() to
find and remove commas.

Alan.
w...@yahoo.ca

Quote
"Jamie VanGulck" <vangu...@civil.queensu.ca> wrote in message

news:a7shkt$kc4$1@knot.queensu.ca...
Quote
> the 'txtFile' if Run Number.csv

> sorry for any inconvinence

> Jamie

Re:End of file use with tab delimited text file


Quote
"Alan Frandsen" <w...@yahoo.ca> wrote in message news:T6qo8.1384
> I had to use Readln to input a line of comma-delimited data and then
create
> a loop to extract individual values.  It's not simple, but it was the only
> way I found.

You could have used the CommaText property of a tStringList, e.g.

Readln (aFile, s);
aStringList.CommaText := s;
NameEdit.Text := aStringList [0];
AddressEdit.Text := aStringList [1];
PhoneEdit.Text := aStringList [2];

Re:End of file use with tab delimited text file


Thanks, I didn't know about the CommaText property.  I just started
programming in Delphi a few months ago (was using Visual Basic 5 before) so
I'm rather new to all the different features.

Thanks again for the advice.
Alan.

Quote
"Bruce Roberts" <b...@bounceitattcanada.xnet> wrote in message

news:jhwo8.5227$a04.27155@tor-nn1.netcom.ca...
Quote

> "Alan Frandsen" <w...@yahoo.ca> wrote in message news:T6qo8.1384

> > I had to use Readln to input a line of comma-delimited data and then
> create
> > a loop to extract individual values.  It's not simple, but it was the
only
> > way I found.

> You could have used the CommaText property of a tStringList, e.g.

> Readln (aFile, s);
> aStringList.CommaText := s;
> NameEdit.Text := aStringList [0];
> AddressEdit.Text := aStringList [1];
> PhoneEdit.Text := aStringList [2];

Other Threads