Re: globals?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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?
    ... 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: 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)
  • Re: GetOpenFilename With MultiSelect Intermittently Returns String
    ... ByVal lpWindowName As String) As Long ... Private Declare Function lstrlen Lib "kernel32" _ ... Private Const OFN_ALLOWMULTISELECT As Long = &H200 ...
    (microsoft.public.excel.programming)