Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Calculator


Reply
 
Thread Tools Display Modes
  #1  
Old 03-28-2003, 05:00 PM
rpgreligion rpgreligion is offline
Regular
 
Join Date: Feb 2003
Location: In front of the comp..duh
Posts: 88
Default 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
Reply With Quote
  #2  
Old 03-28-2003, 06:33 PM
compugeek compugeek is offline
Restricted
 
Join Date: Mar 2003
Location: Where there's no DSL...
Posts: 179
Default

Try:
Code:
Text1.Text = Text1.Text + Whatever number
Reply With Quote
  #3  
Old 03-28-2003, 06:37 PM
compugeek compugeek is offline
Restricted
 
Join Date: Mar 2003
Location: Where there's no DSL...
Posts: 179
Default

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
Reply With Quote
  #4  
Old 03-28-2003, 06:41 PM
compugeek compugeek is offline
Restricted
 
Join Date: Mar 2003
Location: Where there's no DSL...
Posts: 179
Default

sorry... you can replace the + function on the last line to whichever, and use your If...Then statements.
Reply With Quote
  #5  
Old 03-28-2003, 07:03 PM
rpgreligion rpgreligion is offline
Regular
 
Join Date: Feb 2003
Location: In front of the comp..duh
Posts: 88
Default

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
Reply With Quote
  #6  
Old 03-28-2003, 07:39 PM
compugeek compugeek is offline
Restricted
 
Join Date: Mar 2003
Location: Where there's no DSL...
Posts: 179
Default

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?
Reply With Quote
  #7  
Old 03-28-2003, 07:59 PM
Squirm's Avatar
Squirm Squirm is offline
Political Coder

Retired Moderator
* Guru *
 
Join Date: Mar 2001
Location: London, England
Posts: 8,037
Default

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.
__________________
Search the forums | Use [vb][/vb] tags | Still IRCing
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculator Addition DOA General 5 11-23-2002 07:55 AM
Calculator Control dineshjog General 4 11-17-2002 07:25 AM
Making a basic Calculator (+, -, x, /) Juanita General 6 06-02-2002 09:26 PM
love Calculator SkyGirl General 5 12-07-2001 03:21 PM
Calculator physio General 1 10-10-2000 02:24 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->