#184777 - 2008-01-23 01:10 AM
Re: Access one variable with the value of another
[Re: JohnQ]
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4567
Loc: USA
|
I'm sorry I don't have time to explain this, as I needed to be somewhere 10 minutes ago... but see if this gets you going. It's using a two dimensional array...
dim $locations[1,10]
$locations[0,0]="location1"
$Locations[1,0]="c:\windows\some\obscure\path"
$locations[0,1]="location2"
$Locations[1,1]="c:\program files\some\obscure\path"
$x="location2"
for $i=1 to ubound($locations,2)
if $x=$locations[0,$i]
? "X goes here: " + $locations[1,$i]
endif
next
|
|
Top
|
|
|
|
#184779 - 2008-01-23 01:25 AM
Re: Access one variable with the value of another
[Re: Allen]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
|
Lets step away from your specific problem for a moment and get our minds around the concept.. (oooohhhhmmmmmmm) Ready?
You have, for example, two variables. For the excercise, lets call them A and B. Some input tells you which variable to use. Therein lies the problem, variables can't DIRECTLY reference variables.
Try this simple example, and I bet you will be able to solve your problem.
Break On
$ = SetOption('NoVarsInStrings', 'On')
$A = 'Yes'
$B = 'No'
'Which variable would you like to see ("A" or "B")? '
Get $Answer
? ?
$ = Execute('$ActiveValue = $' + $Answer)
'The value of $' $Answer ' is "' $ActiveValue '"' ?
So, now expand this process into your problem. You define, say, 10 values, $A through $J. Your file says to use "E". You use the Execute code to assign the value of E to a working variable - $ActiveValue in this example.
I'll let you play on your own for a bit - it's not too hard to convert this to what you want. Stop back if you need more clues.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
#184784 - 2008-01-23 05:00 AM
Re: Access one variable with the value of another
[Re: Glenn Barnas]
|
JohnQ
Starting to like KiXtart
Registered: 2003-03-04
Posts: 171
|
This is perfect Glen - exactly what I needed.
I should have known that your first post regarding EXECUTE was a clue and not just a suggestion.
|
|
Top
|
|
|
|
#186920 - 2008-04-15 12:03 PM
Re: Access one variable with the value of another
[Re: Glenn Barnas]
|
nocke62
Fresh Scripter
Registered: 2005-03-30
Posts: 12
Loc: Ratingen, Germany
|
Hello Glenn,
thanks for your quick response.
After my post, later on in the evening, I found this solution shown in the example below.
$ = SetOption('NoVarsInStrings', 'On')
$array_1_count = 2
dim $array_1[$array_1_count -1 ,2]
$array_1[0,0] = "language"
$array_1[0,1] = "de"
$array_1[0,2] = "REG_SZ"
$array_1[1,0] = "client"
$array_1[1,1] = "thin"
$array_1[1,2] = "REG_SZ"
$name = "array_1"
$ = Execute('$ActiveValue = $' + $name)
for $i = 0 to $array_1_count -1 step 1
$a_key = $activeValue[$i,0]
$a_val = $activeValue[$i,1]
$a_typ = $activeValue[$i,2]
?
? "a_key: " + $a_key
? "a_val: " + $a_val
? "a_typ: " + $a_typ
next
Thanks
Wolfgang
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 837 anonymous users online.
|
|
|