Компьютерный форум OSzone.net  

Компьютерный форум OSzone.net (http://forum.oszone.net/index.php)
-   Программирование и базы данных (http://forum.oszone.net/forumdisplay.php?f=21)
-   -   где ошибка (http://forum.oszone.net/showthread.php?t=253451)

crindlok 07-02-2013 23:25 2084922

где ошибка
 
Код:

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 2084937

Во первых - после 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;


lxa85 07-02-2013 23:47 2084940

ну так закрой оператор условного перехода точкой с запятой
if <условие> then <оператор> else <оператор> ;
А конструкция begin end -- это операторные скобки. Т.е. когда надо несколько операторов (следи за множественными окончаниями) представить системе как один.
Соотв полный вариант:
Код:

if (<условие>) then begin // открывающая операторная скобка
    <оператор>;
    ...
    <оператор> end // конец оператора, точку с запятой не ставим
else  begin // открывающая операторная скобка
    <оператор>;
    ...
    <оператор> end // конец оператора, точку с запятой не ставим
; //конец оператора if


crindlok 09-02-2013 09:34 2086141

Код:

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, а реальная цифра, проверял с помощью шоумесседж на каждом этапе

iMirRor 12-02-2013 15:10 2088717

Цитата:

Цитата crindlok
Не складывает month_schetchik + month_schetchik2, точнее month_schetchik2 почему-то считает равным 0,хотя он не 0, а реальная цифра, проверял с помощью шоумесседж на каждом этапе »

А можно выложить содержимое файлов, из которых берутся данные?


Время: 12:42.

Время: 12:42.
© OSzone.net 2001-