Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Global variable - Accessing?

Status
Not open for further replies.

milton747

Programmer
Apr 21, 2005
133
US
Hi,

Can anyone help.
I'd like a BASIC function that will return the contents of a global.
See below. GetLocation() is passed the name of a global, and it needs to return the contents of that global. Is there a function that might do that?

Thanks
Milt.


=== Example code ====

Declare
Option Internal
Global MainLocation As String
' MainLocation is initialized later in code
End Declare

' ~~~~~ then later ~~~~

Function GetLocation(locn As String) As String
' Inbound parameter locn conatins: "MainLocation"

GetLocation = ...syntax.... to retrieve the contents of whatever global name was named in "locn"

End Function

============================
 
What exactly do you mean by the contents of the global?

Gerry
 
<<What exactly do you mean by the contents of the global? >>

Declare
Option Internal
Global MainLocation As String
End Declare

REM Initialize MainLocation
MainLocation = "Seattle403"


Then later:

Dim locn As String
Dim s As String

locn = "MainLocation"
s = GetLocation(locn) 'Retrieve contents of global named in locn
REM: s now contains: "Seattle403"

Want to avoid hardcoding "Seattle403" every place.

Thanks
Milton
 
Which VBA are you using that admits a Declare ... End Declare instruction ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top