Calling TextBox1.text from Shared sub main( )

Hey guys,

I'm new at this vb.net thing and have a question. Why can't I make a call to TextBox1.text from within the shared sub main(). It tells me "Cannot refer to an instance member of a class from within a shared method, bla, bla ,bla..."

What am I missing?

Comments

  • try putting the name of the form that the textbox is on in from of the code... for instance instead of Me.textbox1.text put form1.textbox1.text. That is what i did when i had to make my subs shared and it worked... for a while anyway.

    : Hey guys,
    :
    : I'm new at this vb.net thing and have a question. Why can't I make a call to TextBox1.text from within the shared sub main(). It tells me "Cannot refer to an instance member of a class from within a shared method, bla, bla ,bla..."
    :
    : What am I missing?
    :

  • : Hey guys,
    :
    : I'm new at this vb.net thing and have a question. Why can't I make a call to TextBox1.text from within the shared sub main(). It tells me "Cannot refer to an instance member of a class from within a shared method, bla, bla ,bla..."
    :
    : What am I missing?
    :

    Shared methods can only access shared properties. Reason being that the runtime has no way to determine which object instances property value to use.
  • : : Hey guys,
    : :
    : : I'm new at this vb.net thing and have a question. Why can't I make a call to TextBox1.text from within the shared sub main(). It tells me "Cannot refer to an instance member of a class from within a shared method, bla, bla ,bla..."
    : :
    : : What am I missing?
    : :
    :
    : Shared methods can only access shared properties. Reason being that the runtime has no way to determine which object instances property value to use.
    :
    If you need to use the value in your textbox throughout the program, you will need a global variable. Assign the value to the variable, then call the variable, not the textbox.text property.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories