Link to home
Start Free TrialLog in
Avatar of CyberMage
CyberMage

asked on

I Need Help....

I have Delphi 3, and I am a newbie.  The thing I want to know is, why doesn't this program work.  It is supposed to calculate a money value.  When I press F9 to run the program, it gives me this error:

Error in module Unit1: 'END.' missing at end of module.

Here is the program:

procedure TForm1.Button1Click(Sender: TObject);
var
subtot, vat: double;
errcode : integer;
begin
Val(Edit1.Text, subtot, errcode );
if errcode <> 0 then
ShowMessage('You must enter a number!')
else
begin
vat := subtot * 0.175;
Caption := 'VAT = $' + FloatToStr(vat);
Edit2.Text := '$'+ FloatToStr(subtot + vat);
end;
end.

So, what am I doing wrong here?...or if I'm not doing anything wrong; why doesn't it want to work?  Please help.
Avatar of CyberMage
CyberMage

ASKER

Edited text of question.
ASKER CERTIFIED SOLUTION
Avatar of inthe
inthe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
But, why does it need the extra end; for...that is what I don't seem to understand?!
you might also note that developing a clear, consistent indentation style is important part of writing maintainable (and sharable & debugable... :) code, perhaps something like so:

procedure TForm1.Button1Click(Sender: TObject);
var
   subtot, vat: double;
   errcode : integer;
begin
     Val(Edit1.Text, subtot, errcode );
     if errcode <> 0 then
       ShowMessage('You must enter a number!')
     else
     begin {<--another begin here so needs a end; }
          vat := subtot * 0.175;
          Caption := 'VAT = $' + FloatToStr(vat);
          Edit2.Text := '$'+ FloatToStr(subtot + vat);
     end;
end; {<--- added a end here and it works}


end.



GL
Mike
hi
you ask why you need an extra end;
well every begin needs a end; else the compiler wont know where the procedure
finishes.


a procedure()
begin           < begin 1
 dosomething()  
 elseif  
  something then
   begin       < begin 2
    stuff;
   end;        < end 2
 end;          <end 1

end.  <this means end of whole unit


if you are new to delphi maybe its best to get a book that explains the syntax so you understand it better.most delphi books cover the basic syntax
(did you not get some books in the box when you bought delphi called "object pascal language guide ?))
No.  Because I got Delphi 3 for free, from PC Plus magazine (http://www.pcplus.co.uk/).  But, it came with a years tutorial in PDF format.  But, I may still buy a book on it.
:-))
the best mag for software (i also subscribe).
loads of delphi books on amazom at good prices also.
happy learning ;-)
I cannot buy on Amazon, I don't have a credit card...that is what I hate about e-commerce; they expect everyone to have a credit card.  :(