Simple calculation for user entered data in text box

Simple calculation for user entered data in text box

Simple calculation for user entered data in text box

Simple Borland Delphi tutorial demonstrate how to do simple calculation for user entered data in text box. This example shows how to use simple form button click event to do the calculations.

DownloadDownload This Tutorials

Bookmark:

Simple calculation for user entered data in text box

This example demonstrates how to do some basic calculation for given data.

Simple calculation for user entered data in text box using Delphi

On this example just set following three events as shown here.

1) Form create event

procedure TForm1.FormCreate(Sender: TObject);
begin
  { Initialize the labels }
  Label6.Caption:='0.00';
  Label7.Caption:='0.00';
  Label8.Caption:='0.00';
 { Initialize the edit boxes }
  Edit1.Text:='0.00';
  Edit2.Text:='0.00';
end;


2) (Calculate button) on click event

procedure TForm1.Button1Click(Sender: TObject);
Var
  V1, V2, VSum, VSub, VMul : Variant;
begin
    { Variant type variables are very easy to use
    these can hold any data type. And the advantage
    is you can convert them into any data type easily }
    V1:=Edit1.Text;
    V2:=Edit2.Text;
    { function Real() convert the variant to a real no. }
    VSum:=Real(V1)+Real(V2);
    VSub:=Real(V1)-Real(V2);
    VMul:=Real(V1)*Real(V2);
    { Put the results back in labels . . . }
    Label6.Caption:=VSum;
    Label7.Caption:=VSub;
    Label8.Caption:=VMul;
end;


3) (Exit button) on click event.

procedure TForm1.Button2Click(Sender: TObject);
begin
   { Close the form }
   Close;
end;

Download This Delphi Tutorials.

Download materials for this article (Delphi - Tutorials)

Download - Simple-calculation.zipSimple-calculation.zip
       File size: 4 KB, File type: zip
       Total downloads: 173, Upload date: February 02 - 2009

Heinrich Coetzee :: October 16-2009 :: 09:50 AM

Hi,

I would realy like to know how to do divisions as well.

Leave a comment