Link to home
Start Free TrialLog in
Avatar of lidiii
lidiii

asked on

Urgent! Adding 2 numbers

Hello expert.  Still an idiot with delphi and programming.
I need to read 2 numbers (num1 and num2) from the 2 TEdit box, add 700 to the  subtotal and display them in the text label.  
So far, I cannot read num2 in the 2nd tEdit box.
Please help
Thanks

Part of my code:
procedure TForm3.Button1Click(Sender: TObject);
var
num1, num2, total: double;
errcode : integer;
begin
Val(Edit1.Text, num1, Edit2.Text,  errcode );
if errcode <> 0 then
ShowMessage('You must enter a number!')
else
begin
total := num1 + num2 + 700;
Caption := 'Total = $' + FloatToStr(total);
Label1.Caption := 'The result is:  $'+ FloatToStr(Total);
end;
ASKER CERTIFIED SOLUTION
Avatar of Lukasz Zielinski
Lukasz Zielinski
Flag of Poland image

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
why use val if you have TryStrToFloat?

uses SysUtils;

...

procedure TForm3.Button1Click(Sender: TObject);
var num1, num2, total: double;
begin
 if (TryStrToFloat(Edit1.Text, num1) and (TryStrToFloat(Edit2.Text, num2) then
  Label1.CAption := Format('The result is: $%n', [num1 + num2 + 700])
 else
  ShowMessage('not a valid number');
end;