Показать полную графическую версию : где ошибка
crindlok
07-02-2013, 23:25
procedure TForm1.Button3Click(Sender: TObject);
var
year, month_file, month_schetchik_edit : string;
month_conf : textfile;
month_schetchik : double;
begin
year := Edit1.Text[7] + Edit1.Text[8];
month_file := (GetCurrentDir + '\tmp\01.01.' + year + '.tmp');
if FileExists(month_file) then
begin
AssignFile(month_conf,month_file);
Reset(month_conf);
readln(month_conf,month_schetchik_edit);
CloseFile(month_conf);
month_schetchik := StrToFloat(month_schetchik_edit);
end
else
AssignFile(month_conf,month_file);
ReWrite(month_conf);
writeln(month_conf,'0');
CloseFile(month_conf);
end
showmessage(month_schetchik);
end;
ругается на строку showmessage(month_schetchik);
[dcc32 Error] Unit1.pas(219): E2029 ';' expected but identifier 'showmessage' found
[dcc32 Error] Unit1.pas(221): E2029 '.' expected but ';' found
Код еще не дописан, но тут с ендами подозреваю напутал, не компилируется, где ошибка подскажите?
Вообще мне надо несколько if exist then else. Сначало одно проверить, потом другое, никак с ендами не разберусь.
cookie_monster
07-02-2013, 23:42
Во первых - после else должна идти конструкция begin и заканчивается end;
Во вторых showmessage принимает аргументы типа String(Строка) а вы передаете переменную month_schetchik типа Double.
Попробуйте так:
procedure TForm1.Button3Click(Sender: TObject);
var
year, month_file, month_schetchik_edit : string;
month_conf : textfile;
month_schetchik : double;
begin
year := Edit1.Text[7] + Edit1.Text[8];
month_file := (GetCurrentDir + '\tmp\01.01.' + year + '.tmp');
if FileExists(month_file) then
begin
AssignFile(month_conf,month_file);
Reset(month_conf);
readln(month_conf,month_schetchik_edit);
CloseFile(month_conf);
month_schetchik := StrToFloat(month_schetchik_edit);
end
else
begin
AssignFile(month_conf,month_file);
ReWrite(month_conf);
writeln(month_conf,'0');
CloseFile(month_conf);
end;
showmessage(month_schetchik_edit);
end;
ну так закрой оператор условного перехода точкой с запятой
if <условие> then <оператор> else <оператор> ;
А конструкция begin end -- это операторные скобки. Т.е. когда надо несколько операторов (следи за множественными окончаниями) представить системе как один.
Соотв полный вариант:
if (<условие>) then begin // открывающая операторная скобка
<оператор>;
...
<оператор> end // конец оператора, точку с запятой не ставим
else begin // открывающая операторная скобка
<оператор>;
...
<оператор> end // конец оператора, точку с запятой не ставим
; //конец оператора if
crindlok
09-02-2013, 09:34
function StrIsReal(AString: string): Boolean;
var
I: Double;
Code: Integer;
begin
Val(AString, I, Code);
Result := Code = 0;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
year, month_file, month_schetchik_edit : string;
month_conf : textfile;
month_schetchik, month_schetchik2, month_summa : double;
begin
year := Edit1.Text[7] + Edit1.Text[8];
month_file := (GetCurrentDir + '\tmp\01.01.' + year + '.tmp');
if FileExists(month_file) then
begin
AssignFile(month_conf,month_file);
Reset(month_conf);
readln(month_conf,month_schetchik_edit);
CloseFile(month_conf);
if StrIsReal(month_schetchik_edit) then month_schetchik := StrToFloat(month_schetchik_edit);
end
else
begin
AssignFile(month_conf,month_file);
ReWrite(month_conf);
writeln(month_conf,'0');
CloseFile(month_conf);
end
;
month_file := (GetCurrentDir + '\tmp\02.01.' + year + '.tmp');
if FileExists(month_file) then
begin
AssignFile(month_conf,month_file);
Reset(month_conf);
readln(month_conf,month_schetchik_edit);
CloseFile(month_conf);
if StrIsReal(month_schetchik_edit) then month_schetchik2 := StrToFloat(month_schetchik_edit);
end
else
begin
AssignFile(month_conf,month_file);
ReWrite(month_conf);
writeln(month_conf,'0');
CloseFile(month_conf);
end
;
month_summa := month_schetchik + month_schetchik2;
showmessage(FloatToStr(month_summa));
Не складывает month_schetchik + month_schetchik2, точнее month_schetchik2 почему-то считает равным 0,хотя он не 0, а реальная цифра, проверял с помощью шоумесседж на каждом этапе
Не складывает month_schetchik + month_schetchik2, точнее month_schetchik2 почему-то считает равным 0,хотя он не 0, а реальная цифра, проверял с помощью шоумесседж на каждом этапе »
А можно выложить содержимое файлов, из которых берутся данные?
© OSzone.net 2001-2012
vBulletin v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.