Solved

Urgent! Adding 2 numbers

Posted on 2006-10-19
2
215 Views
Last Modified: 2010-04-05
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;
0
Comment
Question by:lidiii
2 Comments
 
LVL 21

Accepted Solution

by:
ziolko earned 500 total points
ID: 17764415
procedure TForm3.Button1Click(Sender: TObject);
var
num1, num2, total: double;
errcode : integer;
begin
Val(Edit1.Text, num1, errcode );
if errcode = 0 then then begin
  Val(Edit2.Text, num2, errcode );  
  if errcode = 0 then begin
    Label1.CAption := Format('The result is: $%n', [num1 + num2 + 700]);
  end else begin
    ShowMessage('You must enter a number into Edit2!')
  end
end else
  ShowMessage('You must enter a number into Edit1!');

ziolko.
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 17764513
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;
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Working this component WebCopy with proxy, help 3 102
code issue 8 185
FMX and jaudiotracker playing memory stream 29 98
Graphics32 under Delphi 10.1 Berlin 2 128
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question