 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
MikeG
Joined: 23 Apr 2004 Posts: 34 Location: Adelaide, South Australia
|
Posted: Mon Aug 09, 2004 3:59 am Post subject: How to resolve variable within a variable |
|
|
Can anybody help witth this problem? Although this example specifically refers to SoundPlay it's a more generic question that could apply to many things.
| Code: | ; retrieve system default sound
RegRead,X,HKCU,AppEvents\Schemes\Apps\.Default\.Default\.current
; Try to play the sound - this doesn't work!
; Note: variable X contains %SystemRoot%\media\Windows XP Ding.wav
; This needs to somehow be resolved to C:\Windows\media\Windows XP Ding.wav
SoundPlay,%X%
; I could do an ugly hack like this, but is there a better, more generic way to resolve variables within variables?
StringReplace,X,X,`%SystemRoot`%,%SystemRoot%
SoundPlay,%X% |
|
|
| Back to top |
|
 |
WhiteCloud
Joined: 19 Jun 2004 Posts: 68
|
Posted: Mon Aug 09, 2004 6:10 am Post subject: |
|
|
Add this line
StringTrimRight, dereffed_var, referenced_var, 0
^that's the only way to do it. It'd be good to work that into the documentation somewhere. Or use any other command that uses variables out and in. _________________ AHK = Hella fun |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10464
|
Posted: Mon Aug 09, 2004 11:58 am Post subject: |
|
|
Good suggestion.
| Quote: | I could do an ugly hack like this, but is there a better, more generic way to resolve variables within variables?
StringReplace,X,X,`%SystemRoot`%,%SystemRoot% |
That too should work, and both are "ugly". In a future version, I'll try to include something like Gui4Cli's DeepTrans option, which allows variable references contained inside other variable references to be resolved.
Since there's a danger of infinite recursion, I should probably have it stop at 1 extra level of resolution, or have the depth configurable. |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10464
|
Posted: Mon Aug 09, 2004 7:31 pm Post subject: |
|
|
Update: I've added a command to accomplish this in the latest version. Please give it a try and let me know if you spot and problems or improvements for it.
Example:
Transform, X, deref, %X% ; Dereference the contents of X. |
|
| Back to top |
|
 |
MikeG
Joined: 23 Apr 2004 Posts: 34 Location: Adelaide, South Australia
|
Posted: Tue Aug 10, 2004 12:00 am Post subject: Problem solved |
|
|
I couldn't get it to work with StringTrimRight, but the new Transform command works. Thanks  |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|