List of variables? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Bernd
Posts: 56
Joined: 03 Sep 2016, 13:56

List of variables?

16 May 2021, 13:17

Instead of repeatedly writing

Code: Select all

if x in A,b,cD, ...
,
I want to 'source out' static variables to a list

Code: Select all

ValuesForX = A,b,cD, ...
and then just write

Code: Select all

if x in ValuesForX
.

It works in Python, but I cannot get it to work in AutoHotkey...
User avatar
mikeyww
Posts: 26856
Joined: 09 Sep 2014, 18:38

Re: List of variables?

16 May 2021, 13:19

Code: Select all

ValuesForX = A,b,cD
x = cD
If x in %ValuesForX%
 MsgBox, 64, Success, It worked!
Example

Code: Select all

x = ValuesForX
If x in ValuesForX,ValuesForY,ValuesForZ,TheseAreLiteralStringsNotVariables
 MsgBox, 64, Success, It worked!
Bernd
Posts: 56
Joined: 03 Sep 2016, 13:56

Re: List of variables?

16 May 2021, 14:25

Ah, forgot the %%...

But I want to do something with the answer, like

Code: Select all

if x in %list%
{
Send xxx
}
else
{
Send yyy
}
return
I tried it, but it does not work.

Edit: It works if I assign %list% as local variable. Have to study how to do it as global variable...
Last edited by Bernd on 16 May 2021, 14:34, edited 1 time in total.
User avatar
mikeyww
Posts: 26856
Joined: 09 Sep 2014, 18:38

Re: List of variables?

16 May 2021, 14:29

You have to define x and list to make it work. Test in Notepad.

Code: Select all

list = a,b,c
x = a
if x in %list%
{
Send xxx
}
else
{
Send yyy
}
Bernd
Posts: 56
Joined: 03 Sep 2016, 13:56

Re: List of variables?

16 May 2021, 15:12

At the beginning of the program? Because I did ...
But so far it works only if I define the %list% after my Hotkey...

Code: Select all

global list
x =
 
Z::
%list% = A,b,cD
<if x in %list%>
<if x not in %list%>
return
User avatar
mikeyww
Posts: 26856
Joined: 09 Sep 2014, 18:38

Re: List of variables?  Topic is solved

16 May 2021, 15:17

You can define variables at the top, or in your hotkey routine. If x is null, then it is not in your list, right?

See the syntax:

Code: Select all

list = a,b,cD

Code: Select all

x = A
list = A,b,cD
 
z::
If x in %list%
 Send xx
Else Send yy
Return
Careful with those % signs! :)
Bernd
Posts: 56
Joined: 03 Sep 2016, 13:56

Re: List of variables?

16 May 2021, 15:54

Yes, did exactly that, didn't work ...

Oh, found my mistake: did not put the list high enough at the top of the program. Now it works. Thank you so much!
Bernd
Posts: 56
Joined: 03 Sep 2016, 13:56

Re: List of variables?

17 May 2021, 12:13

PS: How would I write "not in %list%"?
I tried

Code: Select all

If x != %list%
but it did not work ...
User avatar
mikeyww
Posts: 26856
Joined: 09 Sep 2014, 18:38

Re: List of variables?

17 May 2021, 12:16

I provided the citation in my earlier post, so I presume that you did not examine it.

Code: Select all

x = A
list = A,b,cD
 
z::
If x not in %list%
 Send xx
Else Send yy
Return
Bernd
Posts: 56
Joined: 03 Sep 2016, 13:56

Re: List of variables?

17 May 2021, 12:26

Ah, I was so focused on "in %list%" that I overlooked it ... thanks!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 113 guests