Solved

Urgent! Adding 2 numbers

Posted on 2006-10-19
2
216 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 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

729 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