Hello guys, I am creating simple calculator in VB. My problem is when I multiply two numbers and I get their answer I want to multiply that answer to another number. Code: Private isMultiplying As Boolean = False Private Sub btnMultiply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMultiply.Click If txtNum1.Text.Length <> 0 And txtNum2.Text.Length <> 0 And isMultiplying = False Then Dim answer As Double = multiply(CType(txtNum1.Text, Double), CType(txtNum2.Text, Double)) txtAnswer.Text = answer.ToString() txtNum2.ReadOnly = True ElseIf isMultiplying = True Then Dim ans As Double = multiply(CType(txtNum1.Text, Double), CType(txtAnswer.Text, Double)) txtAnswer.Text = ans.ToString() Else MessageBox.Show("Unesite brojeve u polja", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning) End If Private Function multiply(ByVal num1 As Double, ByVal num2 As Double) As Double Return num1 * num2 End Function Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click revertBool() End Sub Private Sub revertBool() isMultiplying = False End Sub End Sub And now if I multiply 5 * 5 I get 25 which is good, and then I want to enter again num1 to another number ex. 2 then I want to get 50,but I get 10 ???? Sorry If this is confusing ! Thanks!
well there is going to be a problem when you type a letter instead of a number. either use maskedtextboxes or put a CInt() and a try around it