Re: globals?

Tech-Archive recommends: Fix windows errors by optimizing your registry



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.







.



Relevant Pages

  • Re: globals?
    ... And it is not a singleton that word is not used in the VB language. ... 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: common dialog w/api instead of COMDLG32.OCX, possible?
    ... As Long, ByVal lpHelpFile As String, ByVal wCommand As Long, ByVal dwData As ... Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias ... Public Property Get FileNameAs String ...
    (microsoft.public.vb.winapi)
  • Re: Incompatibility between Access 2003 and Access 2002
    ... Private WithEvents mlst As ListBox ... Private mot As ObjectType ... Public DisplayField As String ... Dim prm As DAO.Parameter ...
    (microsoft.public.access.modulesdaovba)