Paul,
Yes, as I mentioned in my first response, make the constants & variables
(the "members") Shared
BTW: Const are by their very nature Shared.
Public NotInheritable Class MyConstants
Public Const ProgId As String = "My Program Id"
Public Shared Readonly Name As String = "Jay"
Public Shared Sub DoWork()
End Sub
Private Sub New()
End Sub
End Class
You would then use MyConstants.Name, MyConstants.ProgId, MyConstants.DoWork
to get at the individual members. The Shared keyword allows you to use the
member without instanciating the class.
http://msdn.microsoft.com/library/de...akeyShared.asp
If I make all the members (subs, functions, fields, properties, events)
shared, then I also mark the class as NotInheritable which prevents other
from inheriting from this class, and add a Private Sub New which prevents
others from instantiating an object of the class. You can use Shared for
classes that are instantiated also, so Notinheritable or Private Sub New may
or may not be used in that case. For example a Parse or From* method, that
creates a new instance of class based on processing some data.
Note: you can use a variable to access a Shared member, however this can
lead to misleading code, such as Thread.Sleep.
Dim aThread As New Thread(...)
aThread.Sleep(100)
It appears in the above that aThread will sleep, while in actuality the
current thread will sleep, as Thread.Sleep is shared method that acts on
Thread.CurrentThread.
Hope this helps
Jay
"Paul" <pw****@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
|I agree that you want to limit (or not use) modules. However, I was
| trying to have user-defined constants without having to instantiate the
| class that the constants reside in. Is that possible?
|
| Also, if you want all your applications to first run a Sub Main, you
| must have a module that contains the Sub Main, right? Or is there a
| way to do that without a module?
|