Error message when converting VB 2003 app to VB 2005

  • Thread starter Thread starter EdPoint
  • Start date Start date
E

EdPoint

As I work to convert a working VB 2003 app that has no error messages to VB
2005, I have been presented with more than 100 instances of the following
warning message:

"Access of shared member, constant member, enum member or nested type
through an instance; qualifying expression will not be evaluated."


Can someone explain what has changed within VB that leads to this warning?
What steps should I follow to address it?
 
VB allows you to access shared methods through an instance of the class. I
am not sure why it does, since it doesn't make sense to do this for shared
methods anyway.

Now you just see a warning about it. All it says is that the variable you
are using to call the shared method/property is not going to get evaluated -
it is going to be ignored. The method will just be called on the class
type. So if your variable was never instantiated, it shouldn't make a
difference, since it can't and won't be used to actually call the method.

It is good practice to call shared methods on the class directory, and not
an instance of it.
 
EdPoint said:
As I work to convert a working VB 2003 app that has no error messages to
VB
2005, I have been presented with more than 100 instances of the following
warning message:

"Access of shared member, constant member, enum member or nested type
through an instance; qualifying expression will not be evaluated."


Can someone explain what has changed within VB that leads to this warning?
What steps should I follow to address it?


The simplest solution is to turn off the warning:

Select "My Project" in solution explorer, -> "Compile" -> "Instance variable
accesses shared member" -> set "Notification" to "None".

Alternatively you can change the method calls to use the name of the class
you want to call the shared member on instead of a variable.
 
Back
Top