resolving a variable

Get help with using AutoHotkey and its commands and hotkeys
toralf
Posts: 792
Joined: 27 Apr 2014, 21:08
Location: Germany

resolving a variable

10 Feb 2015, 17:06

I would like to resolve the following:
The Vars cH, cW, CX, CY hold values to which I want to get
The character H,W,X and Y are contained in an object data as property D.

How do I resolve this in an expression?
%("c" data.d)% doesn't work

If the character H,W,X and Y would be in another var it would be c%var% but I do not want to resolve the object first to var var := data.d
There must be an easy way, but I can't figure it out.

Code: Select all

  data := {}
  data.d := "X"
  CX := "AHK"
  Msgbox, % %("c" data.d)%
ciao
toralf
MJs
Posts: 454
Joined: 23 Sep 2014, 03:29

Re: resolving a variable

10 Feb 2015, 17:43

I don't think that you can get the value of a variable from part string part object without one more line, like you wrote it's for variables enclosed in percent signs
you may get it if it's another object, something like this

Code: Select all

data := {}
info:= {}
data.d := "x"
info.CX := "AHK"
msgbox % info["c" data.d]
you may need to resolve it after all.
good luck
User avatar
jethrow
Posts: 188
Joined: 30 Sep 2013, 19:52
Location: Iowa

Re: resolving a variable

10 Feb 2015, 18:19

toralf wrote:... but I do not want to resolve the object first to var ...
data.d is an expression. The way to deref a string plus expression is to resolve the expression to a variable first, then do a standard double-deref:

Code: Select all

C7 := "AHK"

six := 6
seven := six + 1
MsgBox % C%seven%

; ERROR:
; MsgBox % C%(six + 1)%
; MsgBox % %("C" six + 1)%
However, you can accomplish what you want in AHK v2, since percent signs can deref expressions:

Code: Select all

MsgBox % C%data.d%
toralf
Posts: 792
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: resolving a variable

10 Feb 2015, 21:26

Thank y'all
ciao
toralf

Return to “Ask For Help”

Who is online

Users browsing this forum: RubbeH and 47 guests