Simplifying an A_Args parse?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
chinagreenelvis
Posts: 133
Joined: 19 Oct 2015, 16:21

Simplifying an A_Args parse?

26 Dec 2019, 01:04

Is there a simpler way of doing this:

Code: Select all

For Index, Value in A_Args
{
	If (Value = "asdf")
	{
		Global asdf := 1
	}
	If (Value = "jkl")
	{
		Global jkl := 1
	}
	If (Value = "abcd")
	{
		Global abcd := 1
	}
}
and just convert each argument to its own positive global variable? Or just a quick way of checking if a string exists/doesn't exist in any of the arguments?
Sam_
Posts: 146
Joined: 20 Mar 2014, 20:24

Re: Simplifying an A_Args parse?

07 Jan 2020, 17:47

From docs:
Also note that it is not currently possible to declare a dynamic variable such as global Array%i%.
Prevents you from doing

Code: Select all

For Index, Value in A_Args
	Global %Value%:=1
Which sounds like what you want. Use Switch or make it a bit faster and concise

Code: Select all

For Index, Value in A_Args {
	If (Value="asdf")
		Global asdf:=1
	Else If (Value="jkl")
		Global jkl:=1
	Else If (Value="abcd")
		Global abcd:=1
	}
toralf
Posts: 868
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: Simplifying an A_Args parse?

08 Jan 2020, 06:22

Instead of defining the individual vars as global, I would suggest to set an Settings object as super global and fill it with the command line parameters.
ciao
toralf
Sam_
Posts: 146
Joined: 20 Mar 2014, 20:24

Re: Simplifying an A_Args parse?

08 Jan 2020, 12:58

toralf wrote:
08 Jan 2020, 06:22
Instead of defining the individual vars as global, I would suggest to set an Settings object as super global and fill it with the command line parameters.
Agreed.

Code: Select all

Global Settings:={}
A_Args:=["asdf","jkl","abcd"] ; Just for this example
For Index, Value in A_Args
	Settings[Value]:=1
MsgBox % Settings.jkl ; Test one to see that it was set to 1
chinagreenelvis
Posts: 133
Joined: 19 Oct 2015, 16:21

Re: Simplifying an A_Args parse?

08 Jan 2020, 21:08

Sam_ wrote:
08 Jan 2020, 12:58
toralf wrote:
08 Jan 2020, 06:22
Instead of defining the individual vars as global, I would suggest to set an Settings object as super global and fill it with the command line parameters.
Agreed.

Code: Select all

Global Settings:={}
A_Args:=["asdf","jkl","abcd"] ; Just for this example
For Index, Value in A_Args
	Settings[Value]:=1
MsgBox % Settings.jkl ; Test one to see that it was set to 1
I think this is exactly what I'm looking for. Thanks.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: OrangeCat, Panaku, Rohwedder, roysubs and 314 guests