| | |
Calculator Logic
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2004
Posts: 1
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Jul 2007
Posts: 1
Reputation:
Solved Threads: 0
Please... Post About d code of VB calculator by keypress in keyboard please send to my email jhayrbrizuela2@yahoo.com and the syntax of keypress.. thank you..!!!
•
•
Join Date: Jan 2008
Posts: 65
Reputation:
Solved Threads: 4
•
•
•
•
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
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
Last edited by SolTec; Feb 21st, 2008 at 6:59 pm.
![]() |
Similar Threads
- 40 digit accuracy calculator program (C)
- confused about math operation in pic (Assembly)
- 4 Function Calculator textbox or field control (ASP.NET)
- calculator program (Java)
- relation of mathematics with computer science (Computer Science)
- IF-Then Logic (Java)
- The Calculator (C++)
Other Threads in the VB.NET Forum
- Previous Thread: Visual Studio 2005 Cd's
- Next Thread: can't binding an autoincrement field of mysql data base from vb.net
| Thread Tools | Search this Thread |
.net .net2005 30minutes 2005 2008 access account arithmetic array basic binary bing button buttons c# center check code combobox component connectionstring convert crystalreport data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dropdownlist excel file-dialog folder ftp generatetags google gridview hardcopy image images inline insert intel internet listview mobile monitor ms net networking output passingparameters peertopeervideostreaming picturebox picturebox1 plugin port print printing problem problemwithinstallation project reports" save savedialog searchbox searchvb.net select serial server soap sql table tcp text textbox timer toolbox trim update updown user usercontrol vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web wpf





