#163132 - 2006-06-09 08:33 PM
Re: Can you make a variable's value it's own variable?? $$foo?
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Can you give a real life example of what you are trying to accomplish?
Just as a rough guess VBS Dictionary objects come to mind as a possible solution. I have made several post related to HASHes and Dictionary objects for which you can search.
|
|
Top
|
|
|
|
#163133 - 2006-06-09 08:37 PM
Re: Can you make a variable's value it's own variable?? $$foo?
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
You can built the logic using the execute function.
Code:
break on
$a = "b" $rc = execute ('$$' + $a + ' = "c"') ? "$$b = " + $b
|
|
Top
|
|
|
|
#163134 - 2006-06-09 08:40 PM
Re: Can you make a variable's value it's own variable?? $$foo?
|
thepip3r
Hey THIS is FUN
   
Registered: 2005-03-02
Posts: 350
|
Ok, I have an INI file with these values: Code:
[General] HostName=pc1 Timestamp=1149869020 MAC=000BDB82230F LLU=cameron.wilson OS=Windows XP Professional Ver=Service Pack 2 ScriptRunTime=16
I'm using this loop to get that information: Code:
$General = QS(Split(ReadProfileString($DatedFile,'General',''),chr(10)))
For Each $x in $General $i = ReadProfileString($DatedFile,'General',$x) ? $$x Next
Now my vars in the script match the INI element name. So if $x = 'MAC' in my script, then if I can turn $$x into $MAC, then I cancompare the actual MAC against the one stored in the INI file.... is that any better?
Edited by thepip3r (2006-06-09 08:40 PM)
|
|
Top
|
|
|
|
#163135 - 2006-06-09 08:54 PM
Re: Can you make a variable's value it's own variable?? $$foo?
|
thepip3r
Hey THIS is FUN
   
Registered: 2005-03-02
Posts: 350
|
well after thinking about it a big more, i'm using it in the wrong context for how i use it in PHP. in PHP, when i have an associative array, I use the attempted-to-describe-above method for working with variables instead of array elements:
Code:
$test['1'] = right; $test['2'] = wrong; $test['3'] = either;
foreach ($test as $key => $val) { $$key = $val }
so then, $1 = right, $2 = wrong, etc. again, sorry for asking a question incorrectly. =/
Edited by thepip3r (2006-06-09 08:57 PM)
|
|
Top
|
|
|
|
#163136 - 2006-06-09 09:12 PM
Re: Can you make a variable's value it's own variable?? $$foo?
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Code:
break on $INIfile = "c:\data\scripts\test.ini" $General = Split(ReadProfileString($INIfile,'General',''),chr(10))
For Each $x in $General if $x $val = ReadProfileString($INIfile,'General',$x) $val = "" + $val $CMDstring = '$$' + $x + ' = "' + $val + '"' $rc = execute ($CMDstring) endif Next
? ? $HostName ? $Timestamp ? $MAC ? $LLU ? $OS ? $Ver ? $ScriptRunTime
I just saw your new post. I will ook at it when I get off the phone.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1024 anonymous users online.
|
|
|