non-shared member of a class

M

Mike Johnson

I got the error below, can someone provide the answer in code to the problem
listed below. Thanks.



You have tried to reference a non-shared member of a class from within a
shared method or shared method initialize. The following code provides an
example of such a situation:

Class Sample
Public x as Integer 'An instance member
Public Shared Sub Bar()
x = 10 'Produces the error
End Sub
End ClassThe shared method does not actually operate on any one instance of
the class. Instead, each instance has its own copy of x, which causes the
error.

To correct this error

a.. Provide an explicit instance of the class whose member you wish to
reference. In the example above, provide an explicit instance of the class
containing the copy of x which you wish to set equal to 10.
I can't use shared to fix the problem so please explain in code how to do
the above. Thanks
 
G

Guest

It's kind of funny, when you think about it.

You started your post with the ruse that this was an error you encountered while writing code. You then posted a question verbatim out of a text book.

What's worse, the question has already been answered in your own post. Simply follow the instructions under the line "To correct this error"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top