?
Solved

Urgent! Adding 2 numbers

Posted on 2006-10-19
2
Medium Priority
?
217 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 21

Accepted Solution

by:
ziolko earned 2000 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

Industry Leaders: 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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

752 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