 |
 |

03-28-2003, 05:00 PM
|
|
Regular
|
|
Join Date: Feb 2003
Location: In front of the comp..duh
Posts: 88
|
|
Calculator
|
I'm giving my first attempt at a calculator. I have each number(1,2,3,4,5,6,7,8,9,0) on its own individual button. I also have a label where it displays whichever number. What I want to know is how to add more than 2 numbers. I could easily add two numbers with two text boxes, but that would be cheesy, and I want to add more than two numbers.
Example:
These are the numbers in the display label
5 + 10 + 5 - 5
How would i make it figure out this problem when i click the "=" button?
|
__________________
The biggest mistake in programming is impatience
|

03-28-2003, 06:33 PM
|
|
Restricted
|
|
Join Date: Mar 2003
Location: Where there's no DSL...
Posts: 179
|
|
Try:
Code:
Text1.Text = Text1.Text + Whatever number
|
|

03-28-2003, 06:37 PM
|
|
Restricted
|
|
Join Date: Mar 2003
Location: Where there's no DSL...
Posts: 179
|
|
Then, to figure out the problem, place this in the command button code:
Code:
Dim FirstNum As Variant 'variant works best
Dim SecondNum As Variant
FirstNum = val(text1.Text)
SecondNum = val(text2.Text)
Label1.Caption = FirstNum + SecondNum
|
|

03-28-2003, 06:41 PM
|
|
Restricted
|
|
Join Date: Mar 2003
Location: Where there's no DSL...
Posts: 179
|
|
sorry... you can replace the + function on the last line to whichever, and use your If...Then statements. 
|
|

03-28-2003, 07:03 PM
|
|
Regular
|
|
Join Date: Feb 2003
Location: In front of the comp..duh
Posts: 88
|
|
|
Thanks but i'm trying to avoid text boxes....i have all of the info displayed in one label. I could use text boxes, but then it would be too complicated to add more than two numbers, because i would have to make a ton of text boxes.
|
__________________
The biggest mistake in programming is impatience
|

03-28-2003, 07:39 PM
|
|
Restricted
|
|
Join Date: Mar 2003
Location: Where there's no DSL...
Posts: 179
|
|
|
I goofed again... the first post should be a & instead of a +. Anyway:
I am making a calculator right now... and I am using only one textbox to add as many numbers as the user wants. So, technically, you could do this with textboxes, just experement with If...Then statements and the "&" sign. Are you doing one like the Windows standart calculator?
|
|

03-28-2003, 07:59 PM
|
 |
Political Coder
Retired Moderator * Guru *
|
|
Join Date: Mar 2001
Location: London, England
Posts: 8,037
|
|
|
I believe you are looking for more complex mathematic evaluation? There are two ways to do this:
1) Write your own expression evaluator using operator stacks.
Look up Reverse Polish Notation on google for more ideas.
2) Use the Microsoft Script control to evaluate the equation.
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|