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.
Bookmark:
Simple calculation for user entered data in text box
This example demonstrates how to do some basic calculation for given data.
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)
Simple-calculation.zip
File size: 4 KB, File type: zip
Total downloads: 189, Upload date: February 02 - 2009
Heinrich Coetzee :: October 16-2009 :: 01:50 PM
Hi,
I would realy like to know how to do divisions as well.