Community discussion forum

Help me fix this problem

  • 6 months ago

    The code below is for a mini calculator that add two numbers entered in the two text boxes. I am using visual web developer 2005 express to develop. But it's always showing errors that "Operand1TextBox.Text and Operand2TextBox.Text are not declared"

    Protected Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
    
    End Sub
    
    Protected Sub AddButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim op1, op2, result As Single
        op1 = Convert.ToSingle(Operand1TextBox.Text)
        op2 = Convert.ToSingle(Operand2TextBox.Text)
        result = op1 + op2
        resultLabel.Text = result.ToString()
    End Sub
    
    Post was edited on 19/05/2009 14:06:07 Report abuse
  • 6 months ago

    Why Operand1 and Operand2?

    op1 = Convert.ToSingle(TextBox1.Text)
    op2 = Convert.ToSingle(TextBox2.Text)
    

    This is just fine. You have to pass values by the names of the controls you have used.

    www.consultsarath.info

Post a reply

Enter your message below

Sign in or Join us (it's free).

Want to stay in touch with what's going on? Follow us on twitter!