Re: Dynamic variable
- From: "McKirahan" <News@xxxxxxxxxxxxx>
- Date: Mon, 4 Jul 2005 12:34:45 -0500
"Simon" <spambucket@xxxxxxxxxxx> wrote in message
news:3it71cFn4ihuU1@xxxxxxxxxxxxxxxxx
> Hi,
>
> I was wondering if there was a way of doing something like...
>
> /////////////////////////////////////////////
>
> Dim g_ValA ' global values set somewhere
> Dim g_ValB
> Dim g_ValC
> Dim g_ValD
>
> Function GetValue( sItem )
> GetValue = {sItem}.Value
> End Function
>
> ...
> Function SomeOtherFunction()
>
> GetValue( "g_ValA" ) ' return the value of g_ValA
> GetValue( "g_ValB" ) ' return the value of g_ValB
> GetValue( "g_ValZ" ) ' return an error of some sort as g_ValZ
> does not exist.
>
> End Function
> /////////////////////////////////////////////
>
> where {sItem}is the name of a variable.
> I think it can be acheived in PHP by doing something lke ${val}
>
> Can it be done in VBScript?
>
> Many thanks in advance.
>
> Simon
>
Look at "Eval()".
Option Explicit
Dim g_ValA
g_ValA = "A"
Dim g_ValB
g_ValB = "B"
Dim g_ValC
g_ValC = "C"
Dim g_ValD
g_ValD = "D"
Function GetValue( sItem )
GetValue = Eval(sItem)
End Function
WScript.Echo GetValue( "g_ValA" ) ' return the value of g_ValA
WScript.Echo GetValue( "g_ValB" ) ' return the value of g_ValB
WScript.Echo GetValue( "g_ValZ" ) ' return NOTHING as g_ValZ does not
exist.
.
- Follow-Ups:
- Re: Dynamic variable
- From: Simon
- Re: Dynamic variable
- References:
- Dynamic variable
- From: Simon
- Dynamic variable
- Prev by Date: Dynamic variable
- Next by Date: Re: Parsing binary values in the registry
- Previous by thread: Dynamic variable
- Next by thread: Re: Dynamic variable
- Index(es):
Relevant Pages
|
Loading