Bego
2006-07-03 00:28:40
I was bored so I figured I would make a calculator that looked real good and ran smooth like a program, I have suceeded, maybe I'll make buttons and such next time ;)
[php]{.Script Info:
# ScriptName = Calculator by Bego
# Author = Bego
# Description = Can divide, multiply, add, and subtract.
# Version = 2.0.5
# Date = Saturday, June 24, 2006, 1:20 PM
# Comments = Do the setup or don't - just an extra option
/Script Info}
{ __ _ _ _
/ _\ ___ _ __(_)_ __ | |_ | |__ _ _ _
\ \ / __| '__| | '_ \| __| | '_ \| | | |(_)
_\ \ (__| | | | |_) | |_ | |_) | |_| | _
\__/\___|_| |_| .__/ \__| |_.__/ \__, |(_)
|_| |___/
____
/\ _`\
\ \ \ \ \ __ __ ___
\ \ _ <' /'__`\ /'_ `\ / __`\
\ \ \ \ \/\ __//\ \ \ \/\ \ \ \
\ \____/\ \____\ \____ \ \____/
\/___/ \/____/\/___ \ \/___/
/\____/
\/___/ }
{Instructions:
1. DO THE SETUP ON LINE 52!!
2. Run the script…
3. Follow the instructions in the window which pops up!}
program Calculator;
const
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
////////////////////////SETUP////////////////////////
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
RestartForm = false; {Once the math question is answered, open it up again
to do another question? TRUE or FALSE}
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
////////DO NOT EDIT ANYTHING BELOW THIS POINT////////
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
var
frmDesign : TForm;
Label1 : TLabel;
Label2 : TLabel;
Edit1 : TEdit;
Edit2 : TEdit;
RadioButton1 : TRadioButton;
RadioButton2 : TRadioButton;
RadioButton3 : TRadioButton;
RadioButton4 : TRadioButton;
Button1 : TButton;
firstnum, secondnum, answer : integer;
procedure clickthebutton(sender: TObject);
begin
frmDesign.ModalResult:= mrOk;
end;
procedure InitForm;
begin
frmDesign := CreateForm;
frmDesign.Left := 250;
frmDesign.Top := 114;
frmDesign.BorderStyle := bsSingle;
frmDesign.Caption := 'Calculator';
frmDesign.ClientHeight := 94;
frmDesign.ClientWidth := 236;
frmDesign.Color := clBtnFace;
frmDesign.Font.Color := clWindowText;
frmDesign.Font.Height := -11;
frmDesign.Font.Name := 'MS Sans Serif';
frmDesign.Font.Style := [];
frmDesign.Visible := False;
frmDesign.PixelsPerInch := 96;
Label1 := TLabel.Create(frmDesign);
Label1.Parent := frmDesign;
Label1.Left := 22;
Label1.Top := 14;
Label1.Width := 76;
Label1.Height := 16;
Label1.Caption := 'First Number';
Label1.Font.Color := clWindowText;
Label1.Font.Height := -13;
Label1.Font.Name := 'MS Sans Serif';
Label1.Font.Style := [];
Label1.ParentFont := False;
Label2 := TLabel.Create(frmDesign);
Label2.Parent := frmDesign;
Label2.Left := 1;
Label2.Top := 41;
Label2.Width := 98;
Label2.Height := 16;
Label2.Caption := 'Second Number';
Label2.Font.Color := clWindowText;
Label2.Font.Height := -13;
Label2.Font.Name := 'MS Sans Serif';
Label2.Font.Style := [];
Label2.ParentFont := False;
Edit1 := TEdit.Create(frmDesign);
Edit1.Parent := frmDesign;
Edit1.Left := 102;
Edit1.Top := 12;
Edit1.Width := 49;
Edit1.Height := 21;
Edit1.TabOrder := 8;
Edit2 := TEdit.Create(frmDesign);
Edit2.Parent := frmDesign;
Edit2.Left := 102;
Edit2.Top := 39;
Edit2.Width := 49;
Edit2.Height := 21;
Edit2.TabOrder := 9;
RadioButton1 := TRadioButton.Create(frmDesign);
RadioButton1.Parent := frmDesign;
RadioButton1.Left := 159;
RadioButton1.Top := 1;
RadioButton1.Width := 74;
RadioButton1.Height := 17;
RadioButton1.Caption := 'Multiply';
RadioButton1.TabOrder := 10;
RadioButton2 := TRadioButton.Create(frmDesign);
RadioButton2.Parent := frmDesign;
RadioButton2.Left := 159;
RadioButton2.Top := 16;
RadioButton2.Width := 60;
RadioButton2.Height := 17;
RadioButton2.Caption := 'Divide';
RadioButton2.TabOrder := 11;
RadioButton3 := TRadioButton.Create(frmDesign);
RadioButton3.Parent := frmDesign;
RadioButton3.Left := 159;
RadioButton3.Top := 31;
RadioButton3.Width := 73;
RadioButton3.Height := 17;
RadioButton3.Caption := 'Add';
RadioButton3.TabOrder := 12;
RadioButton4 := TRadioButton.Create(frmDesign);
RadioButton4.Parent := frmDesign;
RadioButton4.Left := 159;
RadioButton4.Top := 46;
RadioButton4.Width := 69;
RadioButton4.Height := 17;
RadioButton4.Caption := 'Subtract';
RadioButton4.TabOrder := 13;
Button1 := TButton.Create(frmDesign);
Button1.Parent := frmDesign;
Button1.OnClick:= @clickthebutton;
Button1.Left := 5;
Button1.Top := 64;
Button1.Width := 224;
Button1.Height := 25;
Button1.Caption := 'Calculate';
Button1.TabOrder := 14;
end;
procedure SafeInitForm;
var
v: TVariantArray;
begin
setarraylength(V, 0);
ThreadSafeCall('InitForm', v);
end;
procedure ShowFormModal;
begin
frmDesign.ShowModal;
end;
procedure SafeShowFormModal;
var
v: TVariantArray;
begin
setarraylength(V, 0);
ThreadSafeCall('ShowFormModal', v);
end;
procedure DoMath;
begin
if(RadioButton1.Checked)then
begin
answer := firstnum * secondnum;
Writeln(inttostr(answer));
end else
if(RadioButton2.Checked)then
begin
if(Edit1.Text = '0') or (Edit2.Text = '0') then
begin
Writeln('Its impossible to divide by zero!');
end else
begin
answer := firstnum / secondnum;
Writeln(inttostr(answer));
end;
end else
if(RadioButton3.Checked)then
begin
answer := firstnum + secondnum;
Writeln(inttostr(answer));
end else
if(RadioButton4.Checked)then
begin
answer := firstnum - secondnum;
Writeln(inttostr(answer));
end else
if(RadioButton1.Checked = false) and
(RadioButton2.Checked = false) and
(RadioButton3.Checked = false) and
(RadioButton4.Checked = false) then
begin
Writeln('You did not select any math style!');
end;
if (RestartForm = true) then
begin
repeat
SafeInitForm;
SafeShowFormModal;
firstnum := strtoint(Edit1.Text);
secondnum := strtoint(Edit2.Text);
answer := 0
DoMath;
until(false);
end else
end;
begin
SafeInitForm;
SafeShowFormModal;
firstnum := strtoint(Edit1.Text);
secondnum := strtoint(Edit2.Text);
answer := 0;
DoMath;
end.[/php]
Its clean code nonetheless, I guess I'll always be known for clean code eh?
[php]{.Script Info:
# ScriptName = Calculator by Bego
# Author = Bego
# Description = Can divide, multiply, add, and subtract.
# Version = 2.0.5
# Date = Saturday, June 24, 2006, 1:20 PM
# Comments = Do the setup or don't - just an extra option
/Script Info}
{ __ _ _ _
/ _\ ___ _ __(_)_ __ | |_ | |__ _ _ _
\ \ / __| '__| | '_ \| __| | '_ \| | | |(_)
_\ \ (__| | | | |_) | |_ | |_) | |_| | _
\__/\___|_| |_| .__/ \__| |_.__/ \__, |(_)
|_| |___/
____
/\ _`\
\ \ \ \ \ __ __ ___
\ \ _ <' /'__`\ /'_ `\ / __`\
\ \ \ \ \/\ __//\ \ \ \/\ \ \ \
\ \____/\ \____\ \____ \ \____/
\/___/ \/____/\/___ \ \/___/
/\____/
\/___/ }
{Instructions:
1. DO THE SETUP ON LINE 52!!
2. Run the script…
3. Follow the instructions in the window which pops up!}
program Calculator;
const
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
////////////////////////SETUP////////////////////////
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
RestartForm = false; {Once the math question is answered, open it up again
to do another question? TRUE or FALSE}
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
////////DO NOT EDIT ANYTHING BELOW THIS POINT////////
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
var
frmDesign : TForm;
Label1 : TLabel;
Label2 : TLabel;
Edit1 : TEdit;
Edit2 : TEdit;
RadioButton1 : TRadioButton;
RadioButton2 : TRadioButton;
RadioButton3 : TRadioButton;
RadioButton4 : TRadioButton;
Button1 : TButton;
firstnum, secondnum, answer : integer;
procedure clickthebutton(sender: TObject);
begin
frmDesign.ModalResult:= mrOk;
end;
procedure InitForm;
begin
frmDesign := CreateForm;
frmDesign.Left := 250;
frmDesign.Top := 114;
frmDesign.BorderStyle := bsSingle;
frmDesign.Caption := 'Calculator';
frmDesign.ClientHeight := 94;
frmDesign.ClientWidth := 236;
frmDesign.Color := clBtnFace;
frmDesign.Font.Color := clWindowText;
frmDesign.Font.Height := -11;
frmDesign.Font.Name := 'MS Sans Serif';
frmDesign.Font.Style := [];
frmDesign.Visible := False;
frmDesign.PixelsPerInch := 96;
Label1 := TLabel.Create(frmDesign);
Label1.Parent := frmDesign;
Label1.Left := 22;
Label1.Top := 14;
Label1.Width := 76;
Label1.Height := 16;
Label1.Caption := 'First Number';
Label1.Font.Color := clWindowText;
Label1.Font.Height := -13;
Label1.Font.Name := 'MS Sans Serif';
Label1.Font.Style := [];
Label1.ParentFont := False;
Label2 := TLabel.Create(frmDesign);
Label2.Parent := frmDesign;
Label2.Left := 1;
Label2.Top := 41;
Label2.Width := 98;
Label2.Height := 16;
Label2.Caption := 'Second Number';
Label2.Font.Color := clWindowText;
Label2.Font.Height := -13;
Label2.Font.Name := 'MS Sans Serif';
Label2.Font.Style := [];
Label2.ParentFont := False;
Edit1 := TEdit.Create(frmDesign);
Edit1.Parent := frmDesign;
Edit1.Left := 102;
Edit1.Top := 12;
Edit1.Width := 49;
Edit1.Height := 21;
Edit1.TabOrder := 8;
Edit2 := TEdit.Create(frmDesign);
Edit2.Parent := frmDesign;
Edit2.Left := 102;
Edit2.Top := 39;
Edit2.Width := 49;
Edit2.Height := 21;
Edit2.TabOrder := 9;
RadioButton1 := TRadioButton.Create(frmDesign);
RadioButton1.Parent := frmDesign;
RadioButton1.Left := 159;
RadioButton1.Top := 1;
RadioButton1.Width := 74;
RadioButton1.Height := 17;
RadioButton1.Caption := 'Multiply';
RadioButton1.TabOrder := 10;
RadioButton2 := TRadioButton.Create(frmDesign);
RadioButton2.Parent := frmDesign;
RadioButton2.Left := 159;
RadioButton2.Top := 16;
RadioButton2.Width := 60;
RadioButton2.Height := 17;
RadioButton2.Caption := 'Divide';
RadioButton2.TabOrder := 11;
RadioButton3 := TRadioButton.Create(frmDesign);
RadioButton3.Parent := frmDesign;
RadioButton3.Left := 159;
RadioButton3.Top := 31;
RadioButton3.Width := 73;
RadioButton3.Height := 17;
RadioButton3.Caption := 'Add';
RadioButton3.TabOrder := 12;
RadioButton4 := TRadioButton.Create(frmDesign);
RadioButton4.Parent := frmDesign;
RadioButton4.Left := 159;
RadioButton4.Top := 46;
RadioButton4.Width := 69;
RadioButton4.Height := 17;
RadioButton4.Caption := 'Subtract';
RadioButton4.TabOrder := 13;
Button1 := TButton.Create(frmDesign);
Button1.Parent := frmDesign;
Button1.OnClick:= @clickthebutton;
Button1.Left := 5;
Button1.Top := 64;
Button1.Width := 224;
Button1.Height := 25;
Button1.Caption := 'Calculate';
Button1.TabOrder := 14;
end;
procedure SafeInitForm;
var
v: TVariantArray;
begin
setarraylength(V, 0);
ThreadSafeCall('InitForm', v);
end;
procedure ShowFormModal;
begin
frmDesign.ShowModal;
end;
procedure SafeShowFormModal;
var
v: TVariantArray;
begin
setarraylength(V, 0);
ThreadSafeCall('ShowFormModal', v);
end;
procedure DoMath;
begin
if(RadioButton1.Checked)then
begin
answer := firstnum * secondnum;
Writeln(inttostr(answer));
end else
if(RadioButton2.Checked)then
begin
if(Edit1.Text = '0') or (Edit2.Text = '0') then
begin
Writeln('Its impossible to divide by zero!');
end else
begin
answer := firstnum / secondnum;
Writeln(inttostr(answer));
end;
end else
if(RadioButton3.Checked)then
begin
answer := firstnum + secondnum;
Writeln(inttostr(answer));
end else
if(RadioButton4.Checked)then
begin
answer := firstnum - secondnum;
Writeln(inttostr(answer));
end else
if(RadioButton1.Checked = false) and
(RadioButton2.Checked = false) and
(RadioButton3.Checked = false) and
(RadioButton4.Checked = false) then
begin
Writeln('You did not select any math style!');
end;
if (RestartForm = true) then
begin
repeat
SafeInitForm;
SafeShowFormModal;
firstnum := strtoint(Edit1.Text);
secondnum := strtoint(Edit2.Text);
answer := 0
DoMath;
until(false);
end else
end;
begin
SafeInitForm;
SafeShowFormModal;
firstnum := strtoint(Edit1.Text);
secondnum := strtoint(Edit2.Text);
answer := 0;
DoMath;
end.[/php]
Its clean code nonetheless, I guess I'll always be known for clean code eh?