Page 1 of 1

Variable name inside a variable

Posted: 24 May 2020, 06:43
by vdmir40
I tried googling it(and actually found one), but it was too hard to understand so I quickly created an account and I'm posting it.

I need to get multiple windows name in multiple variables, but since I can't put a variable name inside a variable, I don't know how I'm going to do it. doing %%varname%% doesn't work.

Code: Select all

...
WinCount = 1

; getting window name by pressing alt + a
!a::
WinGetTitle,%WinCount%,A ; Reason I used %WinCount%: to represent 1, I'll set it more and more 
MsgBox,,,Window name "%%WinCount%%" stored on var %WinCount%
WinCount = %WinCount% + 1
Basically the whole idea: I put the window title in a number which is 1 right now, and I press alt + a again and it stores the window name in 1 + 1 which is 2, and I wanted to make sure that it saves CORRECTLY. And the reason I'm doing this is there could be many names which have to be stored.
If the window name was Windows Explorer, I'm expecting something like this:

Code: Select all

Window name "Windows Explorer" stored on var 1

Re: Variable name inside a variable

Posted: 24 May 2020, 06:53
by boiler
Try this:

Code: Select all

WinCount := 1

; getting window name by pressing alt + a
!a::
WinGetTitle,%WinCount%,A ; Reason I used %WinCount%: to represent 1, I'll set it more and more 
MsgBox,,,% "Window name """ %WinCount% """ stored on var " WinCount
WinCount := WinCount + 1

Re: Variable name inside a variable

Posted: 24 May 2020, 08:39
by Chunjee
I believe these are called Dynamic Variables in the documentation: https://www.autohotkey.com/docs/Language.htm#dynamic-variables