SRL Archive - Research & Development Lounge

SCAR Calculator!


Sandstorm

2009-03-02 18:45:21

Yea. I was bored, so I made a scar calculator.

Any suggestions? Works pretty well, can do decimals and it won't screw up at a division by zero.

Let me know what you think!

program Calculator;

var
EndItemForm : Boolean;
ItemIdform : TForm;
Edit1 : TEdit;
Button1, Button2, Button3, Button4,
Button5, Button6, Button7, Button8,
Button9, Button10, Button11, Button12,
Button13, Button14, Button15, Button16,
Button20, Button21, Button22, SinB,
CosB, TanB, MemS, MemD, MemR : TButton;
Num, T : Integer;
Sign : Array[0..100000] Of Integer;
Number : Array[0..100000] Of Extended;

procedure ItemFormOnClose(Sender : TObject; var Action : TCloseAction);
begin
if (not(ItemIdform.ModalResult = 1)) then
EndItemForm := True;
end;

function IsScarActive: Boolean;
begin
Result:= GetApplication.Active;
end;

Procedure NumbersClick(Sender : TObject);
Begin
If (Edit1.Text = ' 0.') Then
Edit1.Text := '';
Case Sender Of
Button1 : Edit1.Text := Edit1.Text + '1';
Button2 : Edit1.Text := Edit1.Text + '2';
Button3 : Edit1.Text := Edit1.Text + '3';
Button5 : Edit1.Text := Edit1.Text + '4';
Button6 : Edit1.Text := Edit1.Text + '5';
Button7 : Edit1.Text := Edit1.Text + '6';
Button9 : Edit1.Text := Edit1.Text + '7';
Button10 : Edit1.Text := Edit1.Text + '8';
Button11 : Edit1.Text := Edit1.Text + '9';
Button13 : Edit1.Text := Edit1.Text + '0';
Button20 : Edit1.Text := Edit1.Text + '.';
End;
End;

Procedure Clear(Sender : TObject);
Var
I : Integer;
Begin
Edit1.Text := ' 0.';
For I := 0 To T + 1 Do
Number[I] := 0;
For I := 0 To Num + 1 Do
Sign[I] := 0;
Num := 0;
T := 0;
End;

Procedure SQR(Sender : TObject);
Begin
Edit1.Text := FloatToStr(Sqrt(StrToFloat(Edit1.Text)));
End;

Procedure SinCosTan(Sender : TObject);
Begin
Case Sender Of
SinB : Edit1.Text := FloatToStr(Sin(StrToFloat(Edit1.Text)));
CosB : Edit1.Text := FloatToStr(Cos(StrToFloat(Edit1.Text)));
TanB : Edit1.Text := FloatToStr(Tan(StrToFloat(Edit1.Text)));
End;
End;

Function Divisionzzz : Boolean;
Var
I : Integer;
Begin
For I := 0 To T - 1 Do
Begin
Wait(1);
If (Sign[I] = 1) and (Number[I + 1] = 0) Then
Begin
Result := True;
Exit;
End;
End;
End;

Procedure Solve(Sender : TObject);
Var
I, C, H : Integer;
Begin
Number[T] := StrToFloat(Edit1.Text);
If Divisionzzz Then
Begin
Edit1.Text := 'Division by Zero!';
Exit;
End;
For I := 0 To T Do
Begin
If I = 0 Then
Begin
Case Sign[I] Of
1 : Edit1.Text := FloatToStr(Number[I] / Number[i + 1]);
2 : Edit1.Text := FloatToStr(Number[I] * Number[i + 1]);
3 : Edit1.Text := FloatToStr(Number[I] - Number[i + 1]);
4 : Edit1.Text := FloatToStr(Number[I] + Number[i + 1]);
5 : Begin
H := StrToIntDef(Edit1.Text, 3);
Edit1.Text := FloatToStr(Number[I] * Number[0]);
For C := 0 To H - 2 Do
Edit1.Text := FloatToStr(StrToFloat(Edit1.Text) * Number[0]);
Exit;
End;
End;
End else
Begin
Case Sign[I] Of
1 : Edit1.Text := FloatToStr(StrToFloat(Edit1.Text) / Number[i + 1]);
2 : Edit1.Text := FloatToStr(StrToFloat(Edit1.Text) * Number[i + 1]);
3 : Edit1.Text := FloatToStr(StrToFloat(Edit1.Text) - Number[i + 1]);
4 : Edit1.Text := FloatToStr(StrToFloat(Edit1.Text) + Number[i + 1]);
End;
End;
End;
End;

Procedure SetOperation(Sender : TObject);
Begin
Case Sender Of
Button4 : Begin
Sign[Num] := 1;
Number[T] := StrToFloat(Edit1.Text);
Edit1.Text := '';
Inc(Num);
Inc(T);
End;
Button8 : Begin
Sign[Num] := 2;
Number[T] := StrToFloat(Edit1.Text);
Edit1.Text := '';
Inc(Num);
Inc(T);
End;
Button12 : Begin
Sign[Num] := 3;
Number[T] := StrToFloat(Edit1.Text);
Edit1.Text := '';
Inc(Num);
Inc(T);
End;
Button16 : Begin
Sign[Num] := 4;
Number[T] := StrToFloat(Edit1.Text);
Edit1.Text := '';
Inc(Num);
Inc(T);
End;
Button22 : Begin
Sign[Num] := 5;
Number[T] := StrToFloat(Edit1.Text);
Edit1.Text := '';
Inc(Num);
Inc(T);
End;
End;
End;

Procedure MemoryChange(Sender : TObject);
Var
I, T : Integer;
H : String;
C : Array of Integer;
Begin
Case Sender Of
MemD : Begin
C := [0, 1, 2];
If (InIntArray(C, StrToInt(Edit1.Text))) Then
Begin
DeleteIni('Memory' + GetNumbers(Edit1.Text), 'Num', ScriptPath + 'Memory.ini');
Exit;
End;
For I := 0 To 2 Do
Begin
H := ReadIni('Memory' + GetNumbers(Edit1.Text), 'Num', ScriptPath + 'Memory.ini');
If H <> '' Then
DeleteIni('Memory' + GetNumbers(Edit1.Text), 'Num', ScriptPath + 'Memory.ini')
Else
Inc(T);
End;
If T = 3 Then
Edit1.Text := 'No numbers found in memory!';
End;
MemR : Begin
C := [0, 1, 2];
WriteLn(Edit1.Text);
If (InIntArray(C, StrToInt(Edit1.Text))) Then
Readini('Memory' + GetNumbers(Edit1.Text), 'Num', ScriptPath + 'Memory.ini');
For I := 0 To 2 Do
Begin
H := ReadIni('Memory' + GetNumbers(Edit1.Text), 'Num', ScriptPath + 'Memory.ini');
If H <> '' Then
Edit1.Text := H
Else
Inc(T);
End;
If T = 3 Then
Edit1.Text := 'No numbers found in memory!';
End;
MemS : Begin
For I := 0 To 3 Do
Begin
H := ReadIni('Memory' + IntToStr(I), 'Num', ScriptPath + 'Memory.ini');
If H <> '' Then
Begin
Inc(T);
End Else
Begin
Writeini('Memory' + IntToStr(I), 'Num', Edit1.Text, ScriptPath + 'Memory.ini');
Break;
End;
If T >= 3 Then
Begin
Writeini('Memory' + IntToStr(0), 'Num', Edit1.Text, ScriptPath + 'Memory.ini');
Break;
End;
End;
End;
End;
End;

procedure ItemForm;
var
TimeItemForm : Integer;
begin
TimeItemForm := GetSystemTime;
ItemIdform := CreateForm;
with ItemIdform do
begin
OnClose := @ItemFormOnClose;
BorderStyle := bsSingle;
Position := poScreenCenter;
BorderIcons := [biMinimize,biSystemMenu];
ClientWidth := 10 + 10 + 5 + 5 + 10 + 135;
ClientHeight := 260;
Caption := 'Calc';
Color := 14215660;
Font.Color := clWindowText;
Font.Height := -11;
Font.Name := 'MS Sans Serif';
Font.Style := [];
PixelsPerInch := 96;
end;
Edit1 := TEdit.Create(ItemIdform);
with Edit1 do
begin
Parent := ItemIdform;
Left := 10 + 10 + 5 + 5 + 10 + 8;
Top := 8;
Width := 121;
Height := 21;
TabOrder := 8;
Text := ' 0.';
end;
Button1 := TButton.Create(ItemIdform);
with Button1 do
begin
Parent := ItemIdform;
Left := 10 + 10 + 5 + 5 + 10 + 8;
Top := 72;
Width := 25;
Height := 25;
Caption := '1';
TabOrder := 9;
OnClick := @NumbersClick;
end;
SinB := TButton.Create(ItemIdform);
with SinB do
begin
Parent := ItemIdform;
Left := 10 + 10 + 5 + 5 + 10 + 8;
Top := 230;
Width := 30;
Height := 25;
Caption := 'Sine';
TabOrder := 9;
OnClick := @SinCosTan;
end;
CosB := TButton.Create(ItemIdform);
with CosB do
begin
Parent := ItemIdform;
Left := 10 + 10 + 5 + 5 + 10 + 40;
Top := 230;
Width := 40;
Height := 25;
Caption := 'Cosine';
TabOrder := 9;
OnClick := @SinCosTan;
end;
TanB := TButton.Create(ItemIdform);
with TanB do
begin
Parent := ItemIdform;
Left := 10 + 10 + 5 + 5 + 10 + 80;
Top := 230;
Width := 50;
Height := 25;
Caption := 'Tangent';
TabOrder := 9;
OnClick := @SinCosTan;
end;
Button2 := TButton.Create(ItemIdform);
with Button2 do
begin
Parent := ItemIdform;
Left := 10 + 10 + 5 + 5 + 10 + 40;
Top := 72;
Width := 25;
Height := 25;
Caption := '2';
TabOrder := 10;
OnClick := @NumbersClick;
end;
Button3 := TButton.Create(ItemIdform);
with Button3 do
begin
Parent := ItemIdform;
Left := 10 + 10 + 5 + 5 + 10 + 72;
Top := 72;
Width := 25;
Height := 25;
Caption := '3';
TabOrder := 11;
OnClick := @NumbersClick;
end;
Button4 := TButton.Create(ItemIdform);
with Button4 do
begin
Parent := ItemIdform;
Left := 10 + 10 + 5 + 5 + 10 + 104;
Top := 72;
Width := 25;
Height := 25;
Caption := '/';
TabOrder := 12;
OnClick := @SetOperation;
end;
Button5 := TButton.Create(ItemIdform);
with Button5 do
begin
Parent := ItemIdform;
Left := 10 + 10 + 5 + 5 + 10 + 8;
Top := 104;
Width := 25;
Height := 25;
Caption := '4';
TabOrder := 13;
OnClick := @NumbersClick;
end;
Button6 := TButton.Create(ItemIdform);
with Button6 do
begin
Parent := ItemIdform;
Left := 10 + 10 + 5 + 5 + 10 + 40;
Top := 104;
Width := 25;
Height := 25;
Caption := '5';
TabOrder := 14;
OnClick := @NumbersClick;
end;
Button7 := TButton.Create(ItemIdform);
with Button7 do
begin
Parent := ItemIdform;
Left := 10 + 10 + 5 + 5 + 10 + 72;
Top := 104;
Width := 25;
Height := 25;
Caption := '6';
TabOrder := 15;
OnClick := @NumbersClick;
end;
Button8 := TButton.Create(ItemIdform);
with Button8 do
begin
Parent := ItemIdform;
Left := 10 + 10 + 5 + 5 + 10 + 104;
Top := 104;
Width := 25;
Height := 25;
Caption := '*';
TabOrder := 16;
OnClick := @SetOperation;
end;
Button9 := TButton.Create(ItemIdform);
with Button9 do
begin
Parent := ItemIdform;
Left := 10 + 10 + 5 + 5 + 10 + 8;
Top := 136;
Width := 25;
Height := 25;
Caption := '7';
TabOrder := 17;
OnClick := @NumbersClick;
end;
Button10 := TButton.Create(ItemIdform);
with Button10 do
begin
Parent := ItemIdform;
Left := 10 + 10 + 5 + 5 + 10 + 40;
Top := 136;
Width := 25;
Height := 25;
Caption := '8';
TabOrder := 18;
OnClick := @NumbersClick;
end;
Button11 := TButton.Create(ItemIdform);
with Button11 do
begin
Parent := ItemIdform;
Left := 10 + 10 + 5 + 5 + 10 + 72;
Top := 136;
Width := 25;
Height := 25;
Caption := '9';
TabOrder := 19;
OnClick := @NumbersClick;
end;
Button12 := TButton.Create(ItemIdform);
with Button12 do
begin
Parent := ItemIdform;
Left := 10 + 10 + 5 + 5 + 10 + 104;
Top := 136;
Width := 25;
Height := 25;
Caption := '-';
TabOrder := 20;
OnClick := @SetOperation;
end;
Button13 := TButton.Create(ItemIdform);
with Button13 do
begin
Parent := ItemIdform;
Left := 10 + 10 + 5 + 5 + 10 + 8;
Top := 168;
Width := 25;
Height := 25;
Caption := '0';
TabOrder := 21;
OnClick := @NumbersClick;
end;
Button14 := TButton.Create(ItemIdform);
with Button14 do
begin
Parent := ItemIdform;
Left := 10 + 10 + 5 + 5 + 10 + 104;
Top := 168;
Width := 25;
Height := 25;
Caption := '=';
TabOrder := 22;
OnClick := @Solve;
end;
Button15 := TButton.Create(ItemIdform);
with Button15 do
begin
Parent := ItemIdform;
Left := 10 + 10 + 5 + 5 + 10 + 8;
Top := 40;
Width := 89;
Height := 25;
Caption := 'Clear';
TabOrder := 23;
OnClick := @Clear;
end;
Button16 := TButton.Create(ItemIdform);
with Button16 do
begin
Parent := ItemIdform;
Left := 10 + 10 + 5 + 5 + 10 + 104;
Top := 40;
Width := 25;
Height := 25;
Caption := '+';
TabOrder := 24;
OnClick := @SetOperation;
end;
Button20 := TButton.Create(ItemIdform);
with Button20 do
begin
Parent := ItemIdform;
Left := 10 + 10 + 5 + 5 + 10 + 40;
Top := 168;
Width := 58;
Height := 25;
Caption := 'Decimal';
TabOrder := 24;
OnClick := @NumbersClick;
end;
Button21 := TButton.Create(ItemIdform);
with Button21 do
begin
Parent := ItemIdform;
Left := 10 + 10 + 5 + 5 + 10 + 5;
Top := 200;
Width := 68;
Height := 25;
Caption := 'Square Root';
TabOrder := 24;
OnClick := @SQR;
end;
Button22 := TButton.Create(ItemIdform);
with Button22 do
begin
Parent := ItemIdform;
Left := 10 + 10 + 5 + 5 + 10 + 75;
Top := 200;
Width := 60;
Height := 25;
Caption := 'Exponent';
TabOrder := 24;
OnClick := @SetOperation;
end;
MemD := TButton.Create(ItemIdform);
with MemD do
begin
Parent := ItemIdform;
Left := 3;
Top := 72;
Width := 40;
Height := 25;
Caption := 'MemD';
TabOrder := 24;
OnClick := @MemoryChange;
end;
MemR := TButton.Create(ItemIdform);
with MemR do
begin
Parent := ItemIdform;
Left := 3;
Top := 8;
Width := 40;
Height := 25;
Caption := 'MemR';
TabOrder := 24;
OnClick := @MemoryChange;
end;
MemS := TButton.Create(ItemIdform);
with MemS do
begin
Parent := ItemIdform;
Left := 3;
Top := 40;
Width := 40;
Height := 25;
Caption := 'MemS';
TabOrder := 24;
OnClick := @MemoryChange;
end;
WriteLn('ItemForm compiled in ' + IntToStr(GetSystemTime - TimeItemForm) + ' milliseconds!');
end;

procedure SafeItemForm;
var
V : TVariantArray;
begin
SetArrayLength(V, 0);
ThreadSafeCall('ItemForm', V);
end;

procedure ShowItemFormModal;
begin
ItemIdform.ShowModal;
Repeat
If ((ItemIdForm.Focused) and IsKeyDown('9')) Then
Disguise('hi9');
Until(EndItemForm);
end;

procedure SafeShowItemFormModal;
var
V : TVariantArray;
begin
SetArrayLength(V, 0);
ThreadSafeCall('ShowItemFormModal', V);
end;

procedure MainItemForm;
begin
try
SafeItemForm;
SafeShowItemFormModal;
finally
FreeForm(ItemIdform);
except
WriteLn('An error seems to have occurred in: ItemForm');
end;
end;

begin
ClearDebug;
MainItemForm;
if (EndItemForm) then
TerminateScript;
end.

~Sandstorm

Brain

2009-03-02 18:55:53

You have to hit = in between everything, should make it so that if you just hit 6*6*6 it wouldn't just give you 36, instead of 216. Also, maybe add exponents, and change the order of the buttons to match that of the num-pad, confused the crap out of me for a second :pBut good job, works well enough.

Sandstorm

2009-03-02 19:03:36

No, you don't have to hit '=' in between everything? You enter your number, hit the sign you wish to use, then enter your second number. Then hit the '=' button.

And thanks for the suggestions, I'll take a look at them :).

~Sandstorm

neeger

2009-03-02 19:15:19

I started one ages ago havent finish it and i think i never will…
Hmm…. maybe add more functions, like cos, sin, tan :D
The number diappers if you click on -,+,/,* Try to fix that

Sandstorm

2009-03-02 19:19:17

Neeger, it does that on purpose so that you can enter the next number.

Added any number of operations. 3 * 6 + 9 should now work.

~Sandstorm

neeger

2009-03-02 19:23:31

From: Sandstorm
Neeger, it does that on purpose so that you can enter the next number.

Added any number of operations. 3 * 6 + 9 should now work.

~Sandstorm

Oh, but maybe add one more row for operation, example "5*5=25"

Sandstorm

2009-03-02 19:25:15

3 + 3 + 3 - 3 * 3 / 3 + 3 should now technically return the right answer.

As long as you don't exceed 1000 (seriously, how would you manage that?!?!) operations, you won't hit a cap.

Added Exponents and Square Roots.

For Exponents, the number you input the second time is how many times you wish to multiply it.

Ie. 3 Exponent 1 would return 9, and 2 Exponent 2 would return 8.

~Sandstorm

Dervish

2009-03-03 01:19:52

Amazing sandstorm, works good, you should be a SRL Member… But that's not my business… Merely my opinion.

senrath

2009-03-03 01:33:31

Only problem I see is that if you try to use a plain 0 it returns a Divide by zero! error, no matter which operation you're doing. Not a very big problem, but still is one.

Dan Cardin

2009-03-03 06:56:49

the only way to catch divide by zero errors is to simplify the entire equation, else you'll be calling them when there isnt one.

Gu3st...

2009-03-03 10:20:06

0.0 - 0.1 = Divide by zero?

Naum

2009-03-03 11:17:57

Maybe you could use iPow to make everything postative.

Anyways nice try, here is mine:

program New;

Procedure Assign(Sender1 : TObject); Forward;

Var Value : Integer;
Captcha1, Captcha2 : Integer;
Calculation : String;

var
// Calc variables.
frmDesign5 : TForm;
GroupBox1x, GroupBox2x, GroupBox3x, GroupBox4x : TGroupBox;
Label1x, Label2x : TLabel;
Button1x, Button2x, Button3x, Button4x,
Button5x, Button6x, Button7x, Button8x,
Button10x, Button11, Button9, Button12,
Button13, Button14, Button15, Button16 : TButton;
Edit1 : TEdit;

// This form was parsed using: DFM Form Parser v.25 by Ron.
procedure Calc;
var
TimeCalc : Integer;
begin
TimeCalc := GetSystemTime;
frmDesign5 := CreateForm;
with frmDesign5 do
begin
Position := poScreenCenter;
BorderStyle := bsSingle;
BorderIcons := [biMinimize,biSystemMenu];
ClientWidth := 252;
ClientHeight := 234;
Caption := 'Calculat0r Version 0.1 !!!';
Color := clBtnFace;
Font.Color := clWindowText;
Font.Height := -11;
Font.Name := 'MS Sans Serif';
Font.Style := [];
PixelsPerInch := 96;
end;
GroupBox1x := TGroupBox.Create(frmDesign5);
with GroupBox1x do
begin
Parent := frmDesign5;
Left := 0;
Top := 0;
Width := 249;
Height := 233;
Caption :=
' Calculat0r! ' +
' '
TabOrder := 0;
end;
GroupBox2x := TGroupBox.Create(GroupBox1x);
with GroupBox2x do
begin
Parent := GroupBox1x;
Left := 8;
Top := 24;
Width := 233;
Height := 193;
TabOrder := 0;
end;
GroupBox3x := TGroupBox.Create(GroupBox2x);
with GroupBox3x do
begin
Parent := GroupBox2x;
Left := 8;
Top := 48;
Width := 217;
Height := 137;
TabOrder := 0;
end;
Label1x := TLabel.Create(GroupBox3x);
with Label1x do
begin
Parent := GroupBox3x;
Left := 56;
Top := 104;
Width := 84;
Height := 13;
Caption := 'Calculator Ver 0.1';
end;
Label2x := TLabel.Create(GroupBox3x);
with Label2x do
begin
Parent := GroupBox3x;
Left := 56;
Top := 120;
Width := 90;
Height := 13;
Caption := 'By NaumanAkhlaQ';
end;
Button1x := TButton.Create(GroupBox3x);
with Button1x do
begin
Parent := GroupBox3x;
Left := 8;
Top := 8;
Width := 25;
Height := 25;
Caption := '1';
TabOrder := 0;
OnClick := @Assign;
end;
Button2x := TButton.Create(GroupBox3x);
with Button2x do
begin
Parent := GroupBox3x;
Left := 48;
Top := 8;
Width := 25;
Height := 25;
Caption := '2';
TabOrder := 1;
OnClick := @Assign;
end;
Button3x := TButton.Create(GroupBox3x);
with Button3x do
begin
Parent := GroupBox3x;
Left := 88;
Top := 8;
Width := 25;
Height := 25;
Caption := '3';
TabOrder := 2;
OnClick := @Assign;
end;
Button4x := TButton.Create(GroupBox3x);
with Button4x do
begin
Parent := GroupBox3x;
Left := 8;
Top := 40;
Width := 25;
Height := 25;
Caption := '4';
TabOrder := 3;
OnClick := @Assign;
end;
Button5x := TButton.Create(GroupBox3x);
with Button5x do
begin
Parent := GroupBox3x;
Left := 48;
Top := 40;
Width := 25;
Height := 25;
Caption := '5';
TabOrder := 4;
OnClick := @Assign;
end;
Button6x := TButton.Create(GroupBox3x);
with Button6x do
begin
Parent := GroupBox3x;
Left := 88;
Top := 40;
Width := 25;
Height := 25;
Caption := '6';
TabOrder := 5;
OnClick := @Assign;
end;
Button7x := TButton.Create(GroupBox3x);
with Button7x do
begin
Parent := GroupBox3x;
Left := 8;
Top := 72;
Width := 25;
Height := 25;
Caption := '7';
TabOrder := 6;
OnClick := @Assign;
end;
Button8x := TButton.Create(GroupBox3x);
with Button8x do
begin
Parent := GroupBox3x;
Left := 48;
Top := 72;
Width := 25;
Height := 25;
Caption := '8';
TabOrder := 7;
OnClick := @Assign;
end;
Button10x := TButton.Create(GroupBox3x);
with Button10x do
begin
Parent := GroupBox3x;
Left := 88;
Top := 72;
Width := 25;
Height := 25;
Caption := '9';
TabOrder := 8;
OnClick := @Assign;
end;
Button11 := TButton.Create(GroupBox3x);
with Button11 do
begin
Parent := GroupBox3x;
Left := 8;
Top := 104;
Width := 25;
Height := 25;
Caption := '0';
TabOrder := 9;
OnClick := @Assign;
end;
Button9 := TButton.Create(GroupBox3x);
with Button9 do
begin
Parent := GroupBox3x;
Left := 176;
Top := 8;
Width := 33;
Height := 25;
Caption := '+';
TabOrder := 10;
OnClick := @Assign;
end;
Button12 := TButton.Create(GroupBox3x);
with Button12 do
begin
Parent := GroupBox3x;
Left := 176;
Top := 40;
Width := 33;
Height := 25;
Caption := '-';
TabOrder := 11;
OnClick := @Assign;
end;
Button13 := TButton.Create(GroupBox3x);
with Button13 do
begin
Parent := GroupBox3x;
Left := 176;
Top := 72;
Width := 33;
Height := 25;
Caption := 'x';
TabOrder := 12;
OnClick := @Assign;
end;
Button14 := TButton.Create(GroupBox3x);
with Button14 do
begin
Parent := GroupBox3x;
Left := 176;
Top := 104;
Width := 33;
Height := 25;
Caption := '/';
TabOrder := 13;
OnClick := @Assign;
end;
Button15 := TButton.Create(GroupBox3x);
with Button15 do
begin
Parent := GroupBox3x;
Left := 128;
Top := 8;
Width := 33;
Height := 57;
Caption := 'Clear';
TabOrder := 14;
OnClick := @Assign;
end;
Button16 := TButton.Create(GroupBox3x);
with Button16 do
begin
Parent := GroupBox3x;
Left := 128;
Top := 72;
Width := 33;
Height := 25;
Caption := '=';
TabOrder := 15;
OnClick := @Assign;
end;
GroupBox4x := TGroupBox.Create(GroupBox2x);
with GroupBox4x do
begin
Parent := GroupBox2x;
Left := 8;
Top := 8;
Width := 217;
Height := 33;
TabOrder := 1;
end;
Edit1 := TEdit.Create(GroupBox4x);
with Edit1 do
begin
Parent := GroupBox4x;
Left := 0;
Top := 8;
Width := 217;
Height := 21;
TabOrder := 0;
Text := 'Hello! I am Wall-E -- Please Enter your Sum !';
ReadOnly := True;
end;
WriteLn('Calc compiled in ' + IntToStr(GetSystemTime - TimeCalc) + ' milliseconds!');
end;

procedure SafeCalc;
var
V : TVariantArray;
begin
SetArrayLength(V, 0);
ThreadSafeCall('Calc', V);
end;

procedure ShowCalcModal;
begin
frmDesign5.ShowModal;
end;

procedure SafeShowCalcModal;
var
V : TVariantArray;
begin
SetArrayLength(V, 0);
ThreadSafeCall('ShowCalcModal', V);
end;

procedure MainCalc;
begin
try
SafeCalc;
SafeShowCalcModal;
except
WriteLn('An error seems to have occurred in: Calc');
end;
end;


Procedure Solve;
Begin
Case Calculation Of
'Add' : Edit1.Text := IntToStr(Captcha1 + Captcha2);
'Subtract' : Edit1.Text := IntToStr(Captcha1 - Captcha2);
'Multiply' : Edit1.Text := IntToStr(Captcha1 * Captcha2);
'Divide' : Edit1.Text := IntToStr(Captcha1 / Captcha2);
end;
end;

Procedure Assign(Sender1 : TObject);
Begin
Case Sender1 Of
Button1x : Value := 1;
Button2x : Value := 2;
Button3x : Value := 3;
Button4x : Value := 4;
Button5x : Value := 5;
Button6x : Value := 6;
Button7x : Value := 7;
Button8x : Value := 8;
Button9 : Begin
Captcha1 := StrToInt(Edit1.Text);
Edit1.Text := '';
Calculation := 'Add';
Exit;
end;

Button12 : Begin
Captcha1 := StrToInt(Edit1.Text);
Edit1.Text := '';
Calculation := 'Subtract';
Exit;
end;

Button13 : Begin
Captcha1 := StrToInt(Edit1.Text);
Edit1.Text := '';
Calculation := 'Multiply';
Exit;
end;

Button14 : Begin
Captcha1 := StrToInt(Edit1.Text);
Edit1.Text := '';
Calculation := 'Divide';
Exit;
end;

Button10x : Value := 9;
Button11 : Value := 0;
Button15 : Begin
Edit1.Text :='';
Exit;
end;

Button16 : Begin
Captcha2 := StrToInt(Edit1.Text);
Edit1.Text := '';
Solve;
Exit;
end;
end;
if Edit1.Text = 'Hello! I am Wall-E -- Please Enter your Sum !' then
Edit1.Text := '';
Edit1.Text := Edit1.text + IntToStr(Value);
end;


begin
ClearDebug;
GetSelf.WindowState := wsMinimized;
Try
MainCalc;
Finally
FreeForm(frmDesign5);
Except End;

GetSelf.WindowState := wsNormal;
end.

Sandstorm

2009-03-03 17:34:03

Woops, forgot to change that! I'll get right on making it only do that for division. Sorry about that!

Naum, thanks for the model, I'll take a look at how you do it.

If anyone can provide how MS Calculator takes one number and gets Sine/Cosine/Tangent from it, I'll be happy to add it in.

~Sandstorm

senrath

2009-03-03 17:38:34

SCAR has these built in:
function Sin(e : Extended): Extended;
The Sin function is a mathematical function giving the Sine value of X given in radians.

function Cos(e : Extended): Extended;
The Cos function is a mathematical function giving the Cosine value of X given in radians.

function Tan(X: Extended): Extended;
The Tan function is a mathematical function giving the Tangent value of X in radians.

function ArcTan(X: Extended): Extended;
The ArcTan function is a mathematical function giving the value in radians of the Arc Tangent of X.

function ArcSin(X: Extended): Extended;
The ArcSin function is a mathematical function giving the value in radians of the Arc Sine of X.

function ArcCos(X: Extended): Extended;
The ArcCos function is a mathematical function giving the value in radians of the Arc Cosine of X.


Sandstorm

2009-03-03 17:47:21

Ah! Thank you! I'll look into that, and fix the division by zero problem as well in the next version.

Div By Zero fixed.

Sin/Cos/Tan added.

~Sandstorm

Da 0wner

2009-03-04 00:13:13

Guys use IntToStrDef, FloatToStrDef to put failsafes so it dosen't say "Blah is not a valid integer value!".

ian.

2009-03-04 00:20:18

naum.. thanks for telling me that 3+3+3+3+3 = 6.. ;D

you should work on that ;)

nice work Sand ^^

Sandstorm

2009-03-04 18:32:00

New Div by Zero error. Fixed.

Any suggestions?

~Sandstorm

Sandstorm

2009-04-04 13:11:13

Added Memory Save, Delete, and Recall (MemS, MemD, MemR respectively).

MemS will automatically decide which place to save the number in. If all three spots (0-2) are taken, it will overwrite spot number 1.

MemD needs a number (0-2) to decide which one to delete. This is input into the edit box.

MemR functions the same way MemD does, only it returns a number, not deletes it :P.

The numbers are stored in a .ini file. I believe it creates one for you.

~Sandstorm

Griff

2009-04-04 13:23:47

From: Zyt3x
0.0 - 0.1 = Divide by zero?


No? That's 0 divided by something, not divided by 0.

Sandstorm

2009-04-04 13:25:32

From: griff721
No? That's 0 divided by something, not divided by 0.


My calculator used to return a divide by zero for 0.0 - 0.1, as it contained a straight 0.

~Sandstorm

Smarter Child

2009-04-05 01:52:16

Aww, you coded this all yourself, pretty good.

marpis

2009-04-05 11:15:06

its pretty cool :D but it says that sin180 = -0,80115263573383, thus it should be 0

Death12652

2009-04-05 11:30:32

Not bad I would take those suggestions though.

Sandstorm

2009-04-05 12:20:26

Marpis, that's a fault in the way SCAR's Sine function works, not my calculator.

SC, thanks.

Death12652, What suggestions?