The Classic: Cannot refer to an instance member of a class from within a shared method…

I am sure you’ve gotten this before:

Cannot refer to an instance member of a class from within a shared method

Well, instead of all the reasons why, I will just tell you one simple solution:

Pretend you’re doing this:

Public Shared Function getSomething() As Integer
   For Each tControl As Control In FlowLayoutPanel1.Controls    Next

End Function

It will ERROR.

Now Add the form name:

Public Shared Function getSomething() As Integer
   For Each tControl As Control In sampleForm.FlowLayoutPanel1.Controls   Next

End Function

And run again!

The Classic: Cannot refer to an instance member of a class from within a shared method…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s