Solved

Urgent! Adding 2 numbers

Posted on 2006-10-19
2
210 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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now