Solved

Shared class - not sure why i get this warning

Posted on 2006-11-13
8
216 Views
Last Modified: 2010-04-23
I have this class:

1.
Namespace Uni.Web.Data.UserData
    Public Class UserAccess

        Private Shared _DBType As DataProvider
        Public Shared Property DBType() As DataProvider
            Get
                Return _DBType
            End Get
            Set(ByVal value As DataProvider)
                _DBType = value

            End Set
        End Property


        Public Shared Function GetSystems(ByVal userLogin As String) As ArrayList
           .....
        End Function

    End Class
End Namespace

2. In my aspx page, why do I need to do this??
 U_DAL.Uni.Web.Data.UserData.UserAccess.DBType =  U_DAL.DataProvider.IBM  

****If I do this, I get a warning:
        Dim test As U_DAL.Uni.Web.Data.UserData.UserAccess
       test.DBType = U_DAL.DataProvider.IBM  

This is the warning : Access of shared member through an instance; qualifying expression will not be evaluated

3. I looked at this site and I'm not using "new" so, that should work:
http://msdn2.microsoft.com/en-us/library/y6t76186.aspx


0
Comment
Question by:Camillia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 6

Expert Comment

by:riyazthad
ID: 17932948
This is better practice to use shared function or property thru instance variable. It is good to use as class member rather than instance member.

So in your case better to use

U_DAL.Uni.Web.Data.UserData.UserAccess.DBType =  U_DAL.DataProvider.IBM

rather than creating a type variable (instance)
0
 
LVL 6

Expert Comment

by:riyazthad
ID: 17932987
"This is NOT better practice to use shared function or property thru instance variable"

sorry for confusion
0
 
LVL 7

Author Comment

by:Camillia
ID: 17933064
but the type variable (instance) should still work..right? or is it changed in 2.0?
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 6

Expert Comment

by:riyazthad
ID: 17933127
Farzadw,

I think this will make more clear.

http://msdn2.microsoft.com/en-US/library/4hbsxy95.aspx

0
 
LVL 7

Author Comment

by:Camillia
ID: 17933288
it says " 
It is recommended that you do not write code in which you access a shared member through an instance of the class
"

but then in the example, it goes and creates an instance of of "item":
' Create two instances of the class.
    Dim part1 As New Item("keyboard")
    Dim part2 As New Item("monitor")

then calls the shared method : Item.ShareMethod()

0
 
LVL 6

Accepted Solution

by:
riyazthad earned 500 total points
ID: 17933404
Yes

But last line Item.SharedMethod , we are calling directly method without creating instance of type 'Item'.

But first two lines part1 and part2 are instances, but we are not calling its shared method, but calling instance method 'InstanceMethod', which is NOT shared method.

Item.ShareMethod()

is just calling its shared method.

So first two calling are recommenting
but not last one becos that is shared method.

in other words

part1.SharedMethod()
or
part2.sharedMethod()

are not recommenting.


0
 
LVL 7

Author Comment

by:Camillia
ID: 17933436
ah, now I get it..

Good, i thought i was doing something wrong...

But the name is too long without creating an instance.
0
 
LVL 6

Expert Comment

by:riyazthad
ID: 17933445
Yea, Its okay though.

:-)

Thad
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question