Re: globals?
- From: "AMDRIT" <amdrit@xxxxxxxxxxx>
- Date: Mon, 29 Jan 2007 08:39:33 -0600
Cor,
It seems to me that I said the preferred way to do this was to use a class
and not modules and not that this way was better. Singleton must be a word
used in VB, since I learned that word from MS while discovering the new
changes in VS 2002. According to wikipedia, my complicated example is a
singleton http://en.wikipedia.org/wiki/Singleton_pattern.
Cobal programmers questioned how classes where better than procedural
programming too. "Better" is a relative term, and you should be cautious
when throwing that out there. Better, in my view, is how it relates to the
user base. Better, in my view, is how free of bugs my solutions are.
I tell you, I miss VB 5/6 and still toy with it on little things. The
poster asked for the easiest way to do something he has always done, which
is still to use a module. The reason I replied was to share what I thought
everyone else was doing. Apparently, I was wrong. Either way, there is a
group of thought that suggests we not use modules as freely as before, and
to wrap functionality up in classes. My.Settings in the VB world is a prime
example of this statement.
"Cor Ligthert [MVP]" <notmyfirstname@xxxxxxxxx> wrote in message
news:Ox8ZjNhQHHA.3304@xxxxxxxxxxxxxxxxxxxxxxx
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.
.
- References:
- globals?
- From: Smokey Grindle
- Re: globals?
- From: lord . zoltar
- Re: globals?
- From: AMDRIT
- Re: globals?
- From: Cor Ligthert [MVP]
- globals?
- Prev by Date: Re: Validating event not fired when moving from text- to combobox
- Next by Date: Re: Every possible 3 digit combination generator
- Previous by thread: Re: globals?
- Next by thread: Re: globals?
- Index(es):
Relevant Pages
|