Accessing form components from class

sethindeed

Centurion
Joined
Dec 31, 1969
Messages
118
Location
Montreal Canada
I am trying to access some form controls from one of the class I created.

I tried to declare a temp variable as Form1 but when the program reach the following instruction :

Me.Text = tmpForm1.Listbox1.SelectedItem

I am getting an error that told me that my object is not instanced...
Any ideas ?
 
As reference :

If you declare the variable used to contain your form in a module, you will be able to use your form components from a separate class.
Thanx god ! :)
 
you could pass the form as a parameter to the class
if you plan on changing these values use ByRef instead of ByVal for your form parameter

just a suggestion
 
try setting your created class as the startup class and create a new instance of each form you wish to use in the code of your created class with:

Visual Basic:
public myForm1 as New form1

and then reference that variable in form1's code with the namespace of your project such as:

Visual Basic:
myProject1.myClass1.myForm1.blahblahblah

I used a module class to achieve this, see This Thread and scroll to the very end to get the latest working copy after all of the slight modifications...
 
Last edited:
Back
Top