Re: globals?



Amdrit

Why is this better than a module?

And it is not a singleton that word is not used in the VB language.
(While it is as well no singleton in the C world).

Your difficult class written as a nice module could be

Public Module myGlobals

private probjeGlobals as MyGlobabls
etc.
Those are therefore private to the module, only the dim is automaticly
public.

In my idea is a good written VB module therefore much nicer than a so called
often named shared class.

Cor

"AMDRIT" <amdrit@xxxxxxxxxxx> schreef in bericht
news:upnabJYQHHA.1364@xxxxxxxxxxxxxxxxxxxxxxx
I think the new preferred way is to use a singleton. Example
myglobals.instance.somedata="Test String"

public class myglobals

'Singleton Variables
private shared pobjGlobals as MyGlobals

'Instance Variables
private pstrUserName as string
private pintUserID as integer
private pstrSomeData as stirng

'Singleton Creation
shared sub new
pobjGlobals = new MyGlobals
end sub

'Instance Access
public shared readonly Property Instance as MyGlobals
get
return pobjGlobals
end get
end property

'Instance Methods
public function Login(userName as string, password as String) as boolean
'test credentials
'once successful,
me.pstrUserName = 'Some User Name
me.pstrUserID = 'Some User ID
end function

Public Function Add(intVarA as integer, intVarB as integer) as integer
return intvar1 + intvarB
end Function

'Instance Properties
public readonly property UserID as integer
get
Return pintUserID
end get
end property

Public Property SomeData as string
get
return pstrSomeData
end get
set(value as string)
pstrSomeData = value
end set
end property

end class

But yes, modules are still available.


<lord.zoltar@xxxxxxxxx> wrote in message
news:1169839610.011256.212340@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


On Jan 26, 2:20 pm, "Smokey Grindle" <nos...@xxxxxxxxxxxxxx> wrote:
Whats the easiest way to make a global function in VB 2005? The old way
was
make a module, is that still the standard? thanks!

Yup, you can still use modules. You can also use namespaces to group
data.





.



Relevant Pages

  • Re: globals?
    ... singleton http://en.wikipedia.org/wiki/Singleton_pattern. ... Public Module myGlobals ... Those are therefore private to the module, ... myglobals.instance.somedata="Test String" ...
    (microsoft.public.dotnet.languages.vb)
  • Re: globals?
    ... myglobals.instance.somedata="Test String" ... private shared pobjGlobals as MyGlobals ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Singleton Objects
    ... > Private Shared lastid As String ... > End Sub ... >> each call from a client implies this is SingleCall instead of Singleton ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: Updates to a single class instance
    ... I tried to use a singleton, ... public class Collector{ ... private static Collector ref; ...
    (comp.lang.java.programmer)
  • Re: Constructors in Singleton Class
    ... It may mean a singleton that needs initialization or you ... > If the parameters are intended to initialize the singleton and should ... > Private _username As String ... > Private Sub New(ByVal username As String, ...
    (microsoft.public.dotnet.languages.vb)