Re: Static Class Constants (VB 2005)

Tech-Archive recommends: Speed Up your PC by fixing your registry



Beta 2 worked - a public constant could be accessed via the Class Name or
via an Object reference.

Mike.

"schneider" <abc@xxxxxxxxxxx> wrote in message
news:uMF%23zpC$FHA.532@xxxxxxxxxxxxxxxxxxxxxxx
> Yes, this is a change in the VB.NET language and you will be force to
change
> it. C#, and other languages have always done it this way.
>
> I think for the sake of better code clarity it was a good move, also this
> does not require any more work from the developer.
> It's is now obvious if a line of code is calling a shared/static or
instance
> specific method.
> It can be a pain when moving code from 1.0 to 2.0, but at least the error
is
> easy to identify, and easy to fix.
>
> Schneider.
>
>
>
>
> "Michael D. Ober" <obermd.@.alum.mit.edu.nospam> wrote in message
> news:uqatbUC$FHA.516@xxxxxxxxxxxxxxxxxxxxxxx
> > Regardless of Option Explicit and Option Strict settings on a brand new
> form
> > with a single button, I get the error "Access of shared member, constant
> > member, enum member or nested type through an instance; qualifying
> > expression will not be evaluated." on your code sample. VS 2005
Standard
> > RTM.
> >
> > Mike.
> >
> > "m.posseth" <michelp@xxxxxxxxxxxxxxx> wrote in message
> > news:evqiiNC$FHA.2036@xxxxxxxxxxxxxxxxxxxxxxx
> > > Michael
> > >
> > >
> > > i use the release version of Visual studio 2005 ( professional
edition )
> > >
> > > Public Class Form1
> > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> > > System.EventArgs) Handles Button1.Click
> > >
> > > Dim ClassConst As String = XMyClass.ConstantString
> > >
> > > MsgBox(ClassConst)
> > >
> > > Dim myObj = New XMyClass
> > >
> >
> > ''''''''''''' Error is on this line
> > > ClassConst = myObj.ConstantString
> > >
> > > MsgBox(ClassConst)
> > >
> > > End Sub
> > >
> > > End Class
> > >
> > > Class XMyClass
> > >
> > > Public Const ConstantString = "Some Constant String"
> > >
> > > End Class
> > >
> > > this works without anny problems on my dev computer ( no warnings )
> > >
> > > regards
> > >
> > > Michel Posseth [MCP]
> > >
> > >
> > > "Michael D. Ober" <obermd.@.alum.mit.edu.nospam> wrote in message
> > > news:uj9Nk5B$FHA.292@xxxxxxxxxxxxxxxxxxxxxxx
> > > > Is there any way to create a constant in a class that can be used
both
> > > > with
> > > > an instantiated object and without. For example:
> > > >
> > > > dim ClassConst as string = myClass.ConstantString
> > > >
> > > > dim myObj = new MyClass
> > > > ClassConst = myObj.ConstantString
> > > >
> > > > Inside the class MyClass
> > > >
> > > > Class MyClass
> > > >
> > > > public const ConstantString = "Some Constant String"
> > > >
> > > > End Class
> > > >
> > > > In Beta 2, ConstantString was available in either of the above cases
> > > > without
> > > > complaint. In the RTM version, I can't do both. I don't want to
turn
> > off
> > > > the warning as doing so may actually introduce another bug in my
code
> > > > later
> > > > because I didn't see the warning.
> > > >
> > > > Thanks,
> > > > Mike.
> > > >
> > > >
> > > >
> > >
> > >
> > >
> >
> >
> >
>
>
>



.


Quantcast