Re: Static Class Constants (VB 2005)



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.
> >
> >
> >
>
>
>



.