PDA

View Full Version : Need help for visual basic calcutor



tysl2417
09-25-2008, 08:21 PM
I am taking visual basic in school and I need to make a calcutor that only takes one text box but he didnt tell the code for it and he wants us to figure it out and I tried and I cant my calculator at the moment can add two textboxs and display the answer in a label. So its due tomorrow and I need can someone tell me the code to type the numbers in one text box and get the answer in the same one, something to do with strings I know that since like all of you guys are like genius programmers I thought I would come here for help thanks and also can you explain it in the post too?:(h):

XcanadamanX
09-25-2008, 08:56 PM
its not too bad but good luck since its due tomorrow. if you have a specific question then ill answer it but since you're asking for the whole thing to be done, im not going to give you the code. ask specific questions and i'll help

tysl2417
09-25-2008, 09:39 PM
Lets say I typed something in the calcutor when I press mutiply or divide how do you make it disappear so I can type in more numbers and press equals and it gives me the answer? and I only need one text box like a real calcutor.

XcanadamanX
09-25-2008, 09:45 PM
well you have to put the number into a variable and then just wipe the textbox. by doing textboxname.text = ""

tysl2417
09-25-2008, 09:51 PM
what goes in the ""

XcanadamanX
09-25-2008, 09:56 PM
its "

tysl2417
09-25-2008, 09:56 PM
And I dont understand where you put it like under what button would it go under equals or mutiply divide what?

XcanadamanX
09-26-2008, 02:15 AM
when they press one of the operators. +-*/

johns8166
09-27-2008, 07:12 PM
i know it was due yesterday, but ill tell you anyway

declare two variables globally, they will be your first and second number that the user will put in

then, the user will put in a number, and press a button that says firstvalue or something. when the user presses that button, you will code it to firstNumber=val(me.txtWhatever.text) the user will then press /*-+, and the txtbox will clear, and when the user puts in a second number, they will click another button that will do the same thing as the firstvalue button but for the second value. then your program will calculate it, and give the answer in a label.

that was probably really confusing, so ima create a program real quick, and paste the code in a few mins


Public Class frmCalculator

Dim firstValue As Double
Dim secondValue As Double
Dim answer As Double
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Me.Close()
End Sub

Private Sub btnDone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDone.Click
If firstValue = Nothing Then
firstValue = Val(Me.txtValue.Text)
Me.txtValue.Text = Nothing
Else
secondValue = Val(Me.txtValue.Text)
Me.txtValue.Text = Nothing
End If
End Sub

Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
answer = firstValue + secondValue
Me.lblAnswer.Text = answer
firstValue = Nothing
secondValue = Nothing
End Sub

Private Sub btnSubtract_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubtract.Click
answer = firstValue - secondValue
Me.lblAnswer.Text = answer
firstValue = Nothing
secondValue = Nothing
End Sub

Private Sub btnMultiply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMultiply.Click
answer = firstValue * secondValue
Me.lblAnswer.Text = answer
firstValue = Nothing
secondValue = Nothing
End Sub

Private Sub btnDivide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDivide.Click
answer = firstValue / secondValue
Me.lblAnswer.Text = answer
firstValue = Nothing
secondValue = Nothing
End Sub
End Class

http://img253.imageshack.us/my.php?image=15940531sr9.jpg

mariofan12
10-11-2008, 03:51 AM
tysl2417, is ur teacher by any chance mr.graham? cuz my teacher didn't tell us anything either