I did a calculator for a class once.  Right now I can't find it.  Mine was RPN, but I 
think that the same logic would apply.
 
When you hit a number, make the program add the number to the end of the string in the 
textbox.
 
When you hit a function - add, multiply, etc. - have the program store the value in 
the textbox, store the function that you pressed and clear the textbox for the next 
number entry.  
 
When equals is pressed, then you would store the second number in a variable, use a 
case structure (or an if) to find which operation to perform on the two numbers and 
spit out an answer.
 
Then, print the answer to the textbox.  You would have to set all variables to zero to 
start the new problem and have a the program just reprint the existing number in the 
textbox if you haven't yet pressed in a function when the equals sign is pressed.  
 
I will see if I can find the code for the calculator I made is somewhere - but it has 
been a while.
 
I hope this helps.
 
Joe

sramey28 <[EMAIL PROTECTED]> wrote:

Ok Tim I worked with what you told me. Here is my code now. I don't 
understand how you are resetting the cursor back to first character 
before the operator Add ect. is clicked. So then I can't assign that 
number to opt2. Right now I can enter 1 number click + and then 
enter a new number. I then click = and the answer given is the 
second number plus itself. The first number is ignored, so the 
second number is being assigned to opt1 and replacing the first 
number. So the assignment of a number to (opt2) isn't happening. I 
think there should be more to the textchange of the textbox but 
what? 

Private Sub btnNine_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnNine.Click
number = number + "9"
txtEnter.Text = number
End Sub

Private Sub btnDecimal_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnDecimal.Click
number = number + "."
txtEnter.Text = number
End Sub

Public Function Addition() As Integer
answer = opt1 + opt2

End Function

Private Sub btnAdd_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnAdd.Click
txtEnter.Clear()
txtEnter.ResetText()
txtEnter.Text = String.Empty

number = Nothing 'this clears the box so only the next 
number I enter appears, but then I think this cancels out the first 
number.

End Sub

Private Sub txtEnter_TextChanged( _
ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles txtEnter.TextChanged
opt1 = Val(txtEnter.Text)
opt2 = Val(txtEnter.Text) 'where do I put this line.
End Sub

Private Sub btnEqual_Click( _
ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles btnEqual.Click
opt2 = Val(txtEnter.Text) 'does it go here 
Addition()
txtEnter.Text = CStr(answer)
End Sub

--- In [EMAIL PROTECTED], "sramey28" wrote:
> Thanks this should be a big help. 
> 
> 
> --- In [EMAIL PROTECTED], "Tim Rupp" wrote:
> > Why do anything at all with number presses....let your text box 
> hold the
> > value as it is entered from the keystrokes using the 
> TextBox.TextChanged
> > method to gather your input number. Perhaps you want to verify 
> that the
> > keystroke is numeric, decimal point, and perhaps A-E if your 
going 
> to
> > allow hex calculations...but that's your choice. When the 
operand 
> key is
> > hit (+,-,/,*) just take the value of your text display and 
assign 
> that
> > to a temporary value (Operand1 = Val(txtEnter.Text) ) 
> > 
> > At that point I'd highlight the text in the text box and reset 
the
> > cursor to the first character so that the next keystroke entry 
will
> > clear your text box. Then assign the second operand and perform 
the
> > operation in the same manner when the equals key or successive
> > calulation key is struck. At that point you would perform the
> > calculation, assign the result to your result value, and display 
> that
> > value in your text box (once again highlighting the text and 
> placing the
> > cursor at the beginning of the field so that additional entries 
> from the
> > keyboard once again clear your display.
> > 
> > For even more fun, try the RPN calculator type!
> > 
> > Enjoy,
> > tim
> > 
> > 
> > -----Original Message-----
> > From: sramey28 [mailto:[EMAIL PROTECTED] 
> > Sent: Monday, August 30, 2004 4:57 PM
> > To: [EMAIL PROTECTED]
> > Subject: [vbhelp] trying to make calculator with vb.net
> > 
> > 
> > Hi, I'm trying to learn vb.net for work. I only have books and 
> > online class and online help to learn from. I'm trying to make a 
> > simple calculator. here is some of my code. The btnNine_click is 
> > just like procedures for the numbers 0-8. What I need help with 
is 
> > the idea of the Display (txtEnter) showing the right numbers. 
> Right 
> > now I'm only working on addition of numbers. I'm not sure if the 
> > addition function has to be a function or sub. Here are the 
steps 
> to 
> > my problem.
> > 
> > 1. any number is clicked. 
> > 2. This number shows up in display
> > 3. Click the (add +) button
> > 4. previous number disappears, leaving display blank
> > 5. Next Click another number.
> > 6. That one appears in display
> > 7. Now click (equal =) button
> > 8. The answer displayed is First number plus itself.
> > 
> > I think my problem lies in the Addition function line:
> > answer = Double.Parse(number) + Double.Parse(lblNum.Text)
> > both number and lblNum.text point to the same number. 
> > 
> > Main question 
> > How do I get the second number entered recongized and added to 
the 
> > first number entered. This easy if there are two textboxes, but 
> with 
> > one I don't know how to do this. 
> > 
> > Private Sub btnNine_Click( _
> > ByVal sender As System.Object, _
> > ByVal e As System.EventArgs) Handles btnNine.Click
> > number = number + "9"
> > txtEnter.Text = number
> > End Sub
> > 
> > Private Sub btnDecimal_Click( _
> > ByVal sender As System.Object, _
> > ByVal e As System.EventArgs) Handles btnDecimal.Click
> > number = number + "."
> > txtEnter.Text = number
> > End Sub
> > 
> > Public Function Addition() As Integer
> > answer = Double.Parse(number) + Double.Parse(lblNum.Text)
> > lblNum.Text = String.Empty 'cleared for 2nd number 
> enter 
> > number = "" 'tried clear number variable for second 
> number
> > End Function
> > 
> > Private Sub btnAdd_Click( _
> > ByVal sender As System.Object, _
> > ByVal e As System.EventArgs) Handles btnAdd.Click
> > lblNum.Text = CStr(number) 'These two lines are more
> > txtEnter.Text = String.Empty 'of trying to clear the 
> > Addition() 'number 
> > End Sub
> > 
> > Private Sub btnEqual_Click( _
> > ByVal sender As Object, _
> > ByVal e As System.EventArgs) Handles btnEqual.Click
> > txtEnter.Text = CStr(answer)
> > End Sub
> > Thanks sramey28
> > 
> > 
> > 
> > 
> > 
> > '// =======================================================
> > Rules : http://ReliableAnswers.com/List/Rules.asp
> > Home : http://groups.yahoo.com/group/vbHelp/
> > =======================================================
> > Post : [EMAIL PROTECTED]
> > Join : [EMAIL PROTECTED]
> > Leave : [EMAIL PROTECTED]
> > '// =======================================================
> > 
> > 
> > 
> > 
> > Yahoo! Groups Sponsor 
> > 
> > ADVERTISEMENT
> > 
> > 
> 
> 76/
> > 
> 
D=groups/S=1705115364:HM/EXP=1093987023/A=2319501/R=0/SIG=11tq0u909/*
> htt
> > p://www.netflix.com/Default?mqso=60185353&partid=5285298> click 
> here 
> > 
> > > M=298184.5285298.6392945.3001176/D=group
> > s/S=:HM/A=2319501/rand=680771713> 
> > 
> > 
> > _____ 
> > 
> > Yahoo! Groups Links
> > 
> > 
> > * To visit your group on the web, go to:
> > http://groups.yahoo.com/group/vbhelp/
> > 
> > 
> > * To unsubscribe from this group, send an email to:
> > [EMAIL PROTECTED]
> > 
> > 
> > 
> > * Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> > Service . 
> > 
> > 
> > 
> > 
> > [Non-text portions of this message have been removed]






'// =======================================================
Rules : http://ReliableAnswers.com/List/Rules.asp
Home : http://groups.yahoo.com/group/vbHelp/
=======================================================
Post : [EMAIL PROTECTED]
Join : [EMAIL PROTECTED]
Leave : [EMAIL PROTECTED]
'// =======================================================

Yahoo! Groups Links









                
---------------------------------
Do you Yahoo!?
Win 1 of 4,000 free domain names from Yahoo! Enter now.

[Non-text portions of this message have been removed]



------------------------ Yahoo! Groups Sponsor --------------------~--> 
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/k7folB/TM
--------------------------------------------------------------------~-> 


'// =======================================================
    Rules : http://ReliableAnswers.com/List/Rules.asp
    Home  : http://groups.yahoo.com/group/vbHelp/
    =======================================================
    Post  : [EMAIL PROTECTED]
    Join  : [EMAIL PROTECTED]
    Leave : [EMAIL PROTECTED]
'// =======================================================
 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/vbhelp/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

Reply via email to