Valhalla Legends Archive

Programming => General Programming => .NET Platform => Topic started by: CrAz3D on September 27, 2004, 07:33 PM

Title: Reference to a non-shared member requires an object reference.
Post by: CrAz3D on September 27, 2004, 07:33 PM
The above is what VB.NET tells me is wrong when I try to access my RichTextBox that is on Form1.  I am trying to access it from a module.  Are there any special properties that the RTB needs?...or something in the module for that matter?
Title: Re: Reference to a non-shared member requires an object reference.
Post by: K on September 27, 2004, 08:22 PM
you need to reference your richtext box from an object instance, not from the name of the class.


// right
Form1 fMain = new Form1()
fMain.someRichTextBox.DoSomething()

//wrong
Form1.someRichTextBox.DoSomething()
Title: Re: Reference to a non-shared member requires an object reference.
Post by: MyndFyre on September 28, 2004, 01:42 AM
Although, doing it the way K suggests will probably not be what you desire, because it won't change the RTB on your existing form.

Rather, make sure that the module has access to the form instance on which the object you want to modify exists.  For instance, if you have a Form1 instance called myForm1, then in the module, rather than saying Form1.blahblahblah, use myForm1.blahblahblah.

If you don't understand what an object instance is, read the "What's New in VB .NET" section of Help.  Then come back to talk to us.