home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2002 September / PCPlus_193_Laplink2000.iso / Prog / delphi / convertcalc / CONV.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  2002-04-30  |  1.5 KB  |  66 lines

  1. unit CONV;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls;
  8.  
  9. type
  10.   TConv2Form = class(TForm)
  11.     ConvertFromEd: TEdit;
  12.     ConvertToEd: TEdit;
  13.     Label1: TLabel;
  14.     Label2: TLabel;
  15.     CalcBtn: TButton;
  16.     GroupBox1: TGroupBox;
  17.     KmToMilesRBtn: TRadioButton;
  18.     MilesToKmRBtn: TRadioButton;
  19.     CToFRBtn: TRadioButton;
  20.     FToCRBtn: TRadioButton;
  21.     CmToInRbtn: TRadioButton;
  22.     InToCmRBtn: TRadioButton;
  23.     procedure CalcBtnClick(Sender: TObject);
  24.   private
  25.     { Private declarations }
  26.   public
  27.     { Public declarations }
  28.   end;
  29.  
  30. var
  31.   Conv2Form: TConv2Form;
  32.  
  33. implementation
  34.  
  35. {$R *.DFM}
  36.  
  37. procedure TConv2Form.CalcBtnClick(Sender: TObject);
  38. const
  39.      milesToKM = 1.60934;
  40.      KMToMiles = 0.62137;
  41. var
  42.    InputVal, OutputVal : Real;
  43.    Code : integer;
  44.    S : string;
  45. begin
  46.    Val(ConvertFromEd.Text, InputVal, Code );
  47.    If KmToMilesRBtn.checked then
  48.          OutputVal := InputVal * KmToMiles
  49.    else if MilesToKmRBtn.checked then
  50.          OutputVal := InputVal * milesToKM
  51.    else if CToFRBtn.checked then
  52.          OutputVal := ((InputVal * 9) / 5) + 32
  53.    else if FToCRBtn.checked then
  54.          OutputVal := ((InputVal -32) * 5) / 9
  55.    else if CmToInRBtn.checked then
  56.          OutputVal := (InputVal * 0.39370)
  57.    else if InToCmRBtn.checked then
  58.          OutputVal := (InputVal * 2.53999);
  59.  
  60.  
  61.    Str( OutputVal:0:2, S );
  62.    ConvertToEd.Text :=  S;
  63. end;
  64.  
  65. end.
  66.