• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 172
  • Last Modified:

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.
0
CyberMage
Asked:
CyberMage
  • 4
  • 3
1 Solution
 
CyberMageAuthor Commented:
Edited text of question.
0
 
intheCommented:
hi
you a re missing a end;

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.

Regards Barry
0
 
CyberMageAuthor Commented:
But, why does it need the extra end; for...that is what I don't seem to understand?!
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
edeyCommented:
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
0
 
intheCommented:
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 ?))
0
 
CyberMageAuthor Commented:
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.
0
 
intheCommented:
:-))
the best mag for software (i also subscribe).
loads of delphi books on amazom at good prices also.
happy learning ;-)
0
 
CyberMageAuthor Commented:
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.  :(
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now