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;
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
uses SysUtils;
...
procedure TForm3.Button1Click(Sender
var num1, num2, total: double;
begin
if (TryStrToFloat(Edit1.Text,
Label1.CAption := Format('The result is: $%n', [num1 + num2 + 700])
else
ShowMessage('not a valid number');
end;