Hi, first off I'd like to say that this is my first post here. I just finished typing up a long explanation of my problem. And when I submitted it, I wasn't logged in anymore, so I logged in, but then subsequently lost my entire post. All I can say is that is VERY frustrating. Other than that, glad to be here.

I am a student trying to build a working calculator like the windows calculator. Let me say that I have definitely put alot of time into this already and I can't figure it out. I spent around a whole day on this one piece of logic. I have no problem doing 1+1 = 2 but when it comes to doing 1*1*1 = 3 I am encountering some logic trouble.

My code takes the first value entered by the user when the user clicks the plus button and adds it to my variable Operand2. From there, I set Operand1 = operand1 + operand2. With this logic I can add numerous time before hitting the equals button.

That logic works great for the plus button, but when it comes to the subtract, multiply, and divide button, I am running into trouble because 0+1= 1 so that works great. But 0*1=0 and I need it to equal 1, because operand 1 should be equal to the product of operand 1 and 2 so that I can multiply numerous times before hitting the equal button. I hope I've been able to explain my dillema well enough.

Here is my Code, any insights you have would be GREATLY appreciated.

In my btnAdd event handler
Calc.operand2 = convert.ToDouble(me.txtInput.text)
Calc.operator = "add"
me.txtInput.clear
calc.result

In my Calc Class

Public Function Result() As Double
Select Case sOperator
Case is = "add"
Result = dOperand1 + dOperand2
dOperand1 = Result
End Select
End Function

In my btnEquals event handler
Calc.Operand2 = Convert.ToDouble(Me.txtInput.text)
Me.txtInput.Clear()
Me.txtInput.text = Calc.Result.ToString
Calc.Operand1 = Nothing


I hope this post wasn't too long and confusing. :o Thanks for reading

Hi, first off I'd like to say that this is my first post here. I just finished typing up a long explanation of my problem. And when I submitted it, I wasn't logged in anymore, so I logged in, but then subsequently lost my entire post. All I can say is that is VERY frustrating. Other than that, glad to be here.

I am a student trying to build a working calculator like the windows calculator. Let me say that I have definitely put alot of time into this already and I can't figure it out. I spent around a whole day on this one piece of logic. I have no problem doing 1+1 = 2 but when it comes to doing 1*1*1 = 3 I am encountering some logic trouble.

My code takes the first value entered by the user when the user clicks the plus button and adds it to my variable Operand2. From there, I set Operand1 = operand1 + operand2. With this logic I can add numerous time before hitting the equals button.

That logic works great for the plus button, but when it comes to the subtract, multiply, and divide button, I am running into trouble because 0+1= 1 so that works great. But 0*1=0 and I need it to equal 1, because operand 1 should be equal to the product of operand 1 and 2 so that I can multiply numerous times before hitting the equal button. I hope I've been able to explain my dillema well enough.

Here is my Code, any insights you have would be GREATLY appreciated.

In my btnAdd event handler
Calc.operand2 = convert.ToDouble(me.txtInput.text)
Calc.operator = "add"
me.txtInput.clear
calc.result

In my Calc Class

Public Function Result() As Double
Select Case sOperator
Case is = "add"
Result = dOperand1 + dOperand2
dOperand1 = Result
End Select
End Function

In my btnEquals event handler
Calc.Operand2 = Convert.ToDouble(Me.txtInput.text)
Me.txtInput.Clear()
Me.txtInput.text = Calc.Result.ToString
Calc.Operand1 = Nothing


I hope this post wasn't too long and confusing. :o Thanks for reading

your code is a bit confusing, since the gui for a calulator is just capturing input of the numbers. forcing the user to enter only numbers (IsNumeric) function will keep that.

Dim i as Integer
i = txtTextboxtName.text
Logic if the + addition or - subtraction or *or multiplication or division / buttons are pressed to add, subtract, multiply or divide your integer. Each time you press the +,-,* or / the txtTextboxName.text is string.empty or "", so you don't have 1 =1+ 11, instead of 1 +1 pressing equal would give you 2

You can also format your number by using CDbl for double or CInt for Integer or CStr for String

i += i in addition
i -= i in subtraction
i *= i in multiplication
i /= i in division

if you hit = then a total of i is made
if you hit +, -, * or / the i value is continued

txtTextboxName. text = string.empty
i = 0
to start over

This article has been dead for over six months. Start a new discussion instead.