[VB] Noob need Help

Discussion in 'Mixed Languages' started by splinter_, Feb 17, 2013.

  1. splinter_

    splinter_ MDL Novice

    Dec 17, 2012
    19
    3
    0
    #1 splinter_, Feb 17, 2013
    Last edited by a moderator: Apr 20, 2017
    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!
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. splinter_

    splinter_ MDL Novice

    Dec 17, 2012
    19
    3
    0
    Oh I figure it out. I didn't set isMultiplying = True before ElseIf statement :)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. PAYMYRENT

    PAYMYRENT MDL Developer

    Jul 28, 2009
    1,462
    418
    60
    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