Reference to a non-shared member requires an object reference

Hi all,

I have an application with two forms, in which the following occurrs:
1. MainForm opens ChildForm.  
2. Before ChildForm closes it should call to a sub in MainForm.
3. This sub should take parameters passed from ChildForm and populate a TreeView within MainForm.

This worked fine when the project was configured as a Windows Application. However, it has become necessary to change this to a Class Library. After doing so, the call to the sub in MainForm errors out with "Reference to a non-shared member requires an object reference".  If I change the sub to Public Shared, it cannot manipulate the control it is supposed to populate.  I tried creating an object reference from the ChildForm as it suggests but when I step through the code, it seems to work but nothing populates in the TreeView.

Any help will be extremely helpful.  Thanks!



Public Class MainForm
...
    ' Populate the TreeView with the data from ChildForm
    Private Sub GetInfoFromChildForm(ByVal Info as string)

        ...

    End Sub
...
End Class


Public Class ChildForm
...
    ' Pass the info to MainForm
    Private Sub PassInfo()

        ' Call the sub in MainForm that populates the MainForm TreeView
        MainForm.GetInfoFromChildForm(InfoToPass)

    End Sub
...
End Class
esdTeamstersAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AlexFMCommented:
Public Class MainForm

...
    ' create and show ChildForm
     dim childForm as ChildForm
     childForm = new ChildForm()
     childForm.mainForm = Me
     ...

...
    ' Populate the TreeView with the data from ChildForm
    Private Sub GetInfoFromChildForm(ByVal Info as string)

        ...

    End Sub
...
End Class


Public Class ChildForm

    public mainForm as MainForm
...
    ' Pass the info to MainForm
    Private Sub PassInfo()

        ' Call the sub in MainForm that populates the MainForm TreeView
        mainForm.GetInfoFromChildForm(InfoToPass)

    End Sub
...
End Class
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
esdTeamstersAuthor Commented:
No luck so far. I get an "Object reference not set to an instance of an object" error at the line that calls the MainForm sub.  I tried changing:

public mainForm as MainForm

to

public mainForm as New MainForm

...and it doesn't error out on me, but doesn't populate the control either.
0
esdTeamstersAuthor Commented:
My mistake,  I got it to work.  Thanks for the quick response!!
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

AlexFMCommented:
dim childForm as ChildForm
childForm = new ChildForm()
childForm.mainForm = Me                  '  did you add this line?

Last line sets reference to main form in child form.

public mainForm as MainForm   ' no need in New

If you don't khow where to apply this code, post code fragment where you create and show child form from main form.

0
wiswalldCommented:
Thats not it. What I mean is if I put a button on form1 (lets say) and type in form2.Button2_Click after I put in Form2. I should get a list of options like controls on Form2. I do not see them and if I just type them in I get the error.
0
wiswalldCommented:
Sorry I posted to the wrong question.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.