locked
Name ________ is not declared

    Question

  • Hello I just recieved Visual Basic Express and am attempting my third program of any kind off the tutorial.

    Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

     

    Dim A As Double = Textbox1.Text

    Dim B As Double = Textbox2.Text

    MsgBox(A + B)

    MsgBox(A - B)

    MsgBox(A * B)

    MsgBox(A / B)

    End Sub

    End Class

     

    I've followed the instructions exactly but it keeps saying "Name 'textbox1.text" is not declared and "Name textbox2.text" is not declared

    Thanks!

     

    Sunday, April 09, 2006 11:58 PM

Answers

  • This means that your form does not contain two textboxes called textbox1 and textbox2.  Have you added textboxes to the form in design mode ?

    ALso, you really want to add this code to a button click event handler.  Otherwise, it will run when the form loads, you'd need to prepopulate the textboxes with numbers, you could not change them, and the whole exercise would be kind of pointless.  Add two textboxes to the form.  Add a button.  Double click on the button and move this code into the method that is created.  Then it should work when you push the button, excepting that this code does not check to make sure the values in the textboxes are numbers, if they are not, it will crash.

     

    Monday, April 10, 2006 12:07 AM

All replies

  • This means that your form does not contain two textboxes called textbox1 and textbox2.  Have you added textboxes to the form in design mode ?

    ALso, you really want to add this code to a button click event handler.  Otherwise, it will run when the form loads, you'd need to prepopulate the textboxes with numbers, you could not change them, and the whole exercise would be kind of pointless.  Add two textboxes to the form.  Add a button.  Double click on the button and move this code into the method that is created.  Then it should work when you push the button, excepting that this code does not check to make sure the values in the textboxes are numbers, if they are not, it will crash.

     

    Monday, April 10, 2006 12:07 AM
  • whoa i didn't even know what design mode was. But i figured it out thanks!
    Monday, April 10, 2006 12:22 AM