AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to resolve variable within a variable

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
MikeG



Joined: 23 Apr 2004
Posts: 34
Location: Adelaide, South Australia

PostPosted: Mon Aug 09, 2004 3:59 am    Post subject: How to resolve variable within a variable Reply with quote

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
View user's profile Send private message AIM Address
WhiteCloud



Joined: 19 Jun 2004
Posts: 68

PostPosted: Mon Aug 09, 2004 6:10 am    Post subject: Reply with quote

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
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10464

PostPosted: Mon Aug 09, 2004 11:58 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10464

PostPosted: Mon Aug 09, 2004 7:31 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
MikeG



Joined: 23 Apr 2004
Posts: 34
Location: Adelaide, South Australia

PostPosted: Tue Aug 10, 2004 12:00 am    Post subject: Problem solved Reply with quote

I couldn't get it to work with StringTrimRight, but the new Transform command works. Thanks Smile
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group