Basic Calculator

Hey
I've written a program for a basic calculator with the intention to progress the project on to more advanced calculations. I was wondering whether someone could help me with a couple of small problems I am having at the moment.
1) When I enter a number into the edit box and then press an operator such as + the number clears from the edit box so that the next number in the sum can be entered but the cursor doesn't return to the edit box and you have to physically click on it to be able to type again... is there any way to get round this so that the cursor automatically returns when the edit box is empty?

2)my calculator only deals with two number sums e.g. 1+1 = 2 is there an easy way to get it to deal with sums of more than two numbers and perhaps multiple operators?

3)The Previous calculation dosen't clear when you start entering a new calculation so you need to press the C key everytime is there also a way around this?.
I am including my source code in case you need to see it before you are able to help...
Thanks for your time
Kelly

[/code]
var
Form1: TForm1;

implementation

{$R *.dfm}

var
Op1, Op2 : Real;
Code, operator, DecPoint: Integer;
s : string;

procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.Text := Edit1.Text + '1';
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Edit1.Text := Edit1.Text + '2';
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
Edit1.Text := Edit1.Text + '3';
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
Edit1.Text := Edit1.Text + '4';
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
Edit1.Text := Edit1.Text + '5';
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
Edit1.Text := Edit1.Text + '6';
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
Edit1.Text := Edit1.Text + '7';
end;

procedure TForm1.Button8Click(Sender: TObject);
begin
Edit1.Text := Edit1.Text + '8';
end;

procedure TForm1.Button9Click(Sender: TObject);
begin
Edit1.Text := Edit1.Text + '9';
end;

procedure TForm1.DecimalClick(Sender: TObject);
begin
If DecPoint = 0 then
Edit1.Text := Edit1.Text + '.';
DecPoint := 1;
end;

procedure TForm1.Operator1Click(Sender: TObject);
begin
Val (Edit1.Text, Op1, Code);
Edit1.Clear;
Operator := 1;
DecPoint := 0;
end;

procedure TForm1.Operator2Click(Sender: TObject);
begin
Val (Edit1.Text, Op1, Code);
Edit1.Clear;
Operator := 2;
DecPoint := 0;
end;

procedure TForm1.Operator3Click(Sender: TObject);
begin
Val (Edit1.Text, op1, Code);
Edit1.Clear;
operator := 3;
DecPoint := 0;

end;

procedure TForm1.Operator4Click(Sender: TObject);
begin
Val (Edit1.Text, op1, Code);
Edit1.Clear;
operator := 4;
DecPoint := 0;
end;

procedure TForm1.Operator5Click(Sender: TObject);
begin
Val (Edit1.Text, op2, Code);
If operator = 1 then
op1 := op1 + op2 else
if operator = 2 then
op1 := op1 - op2 else
If operator = 3 then
op1 := op1 * op2 else
If operator = 4 then
op1 := op1/op2 else
If operator = 5 then
op1 := (op1/100)*op2;
Str(op1:2:2,s);
Edit1.Text := s;
DecPoint := 0;
end;

procedure TForm1.CancelClick(Sender: TObject);
begin
Edit1.Clear;
op1 := 0;
op2 := 0;
DecPoint :=0;
end;

procedure TForm1.PercentClick(Sender: TObject);
begin
Val (Edit1.Text, Op1, Code);
Edit1.Clear;
Operator := 5;
DecPoint := 0;
end;

procedure TForm1.CancelEntryClick(Sender: TObject);
begin
edit1.Clear;
end;

end.
[code]

Comments

  • Hey there....

    Wow a female programmer..! (Dont take that as an insult if your American or if you are just called kelly and is a boy. It because im English :p)

    I did a calculater at college in VB il post the code on here tomz if you wish. Or do you want me to explain a method to you?
  • Hey,
    Yes I am a female, didn't realise that was shocking...
    I don't have much experience with VB.. Will it be relevant seeing as my program is in Delphi...?
    Don't suppose You're able to help with another programming issue?
    I need to write a program that could read a function from a file and display the graph etc
    Don't have a clue where to start!
    Cheers
    Kel x



    : Hey there....


    :
    : Wow a female programmer..! (Dont take that as an insult if your American or if you are just called kelly and is a boy. It because im English :p)
    :
    : I did a calculater at college in VB il post the code on here tomz if you wish. Or do you want me to explain a method to you?
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories