读书人

文本数据不能循环读取解决办法

发布时间: 2013-04-09 16:45:09 作者: rapoo

文本数据不能循环读取
我写的一段代码,循环读取text中数据,但是红色部分循环一次后不读取第二行的数据,即i+1行的数据。请大侠指点
procedure Tfsjdq.RzToolButton2Click(Sender: TObject);
var txtlist:TStringList;
i,j,acount:integer;
sdata:TStringList;

begin
memo1.Clear;
txtlist:=TStringList.create;
sdata:=TStringList.create;
txtlist.LoadFromFile(opendialog1.filename);
j:=1;
i:=5;

while i<= txtlist.count-1 do
begin
if copy(txtlist.strings[i],25,11)='Debit Total' then
begin
exit;
end;

if copy(txtlist.strings[i],2,6)='gltrrp' then
begin
i:=i+5;
j:=j+1;
end;
memo1.Lines.Add(txtlist.strings[i] + ' ' + '凭证标志' + inttostr(j));
acount:=ExtractStrings([' '],[' '],PAnsiChar(AnsiString(txtlist.strings[i])),sdata);
for acount:=0 to acount-1 do
begin
showmessage(sdata[acount]);

end;
i:=i+1;

end;

end;

[解决办法]
这样修改:
acount不要用作循环变量

procedure Tfsjdq.RzToolButton2Click(Sender: TObject);
var txtlist:TStringList;
i,j,k, acount:integer;
sdata:TStringList;

begin
memo1.Clear;
txtlist:=TStringList.create;
sdata:=TStringList.create;
txtlist.LoadFromFile(opendialog1.filename);
j:=1;
i:=5;

while i<= txtlist.count-1 do
begin
if copy(txtlist.strings[i],25,11)='Debit Total' then
begin
exit;
end;

if copy(txtlist.strings[i],2,6)='gltrrp' then
begin
i:=i+5;
j:=j+1;
end;
memo1.Lines.Add(txtlist.strings[i] + ' ' + '凭证标志' + inttostr(j));
acount:=ExtractStrings([' '],[' '],PAnsiChar(AnsiString(txtlist.strings[i])),sdata);
for k :=0 to acount-1 do
begin
showmessage(sdata[k]);

end;
i:=i+1;

end;

end;

读书人网 >.NET

热点推荐