Help needed for a list of radio buttons

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
DyNama
Posts: 14
Joined: 26 Jul 2014, 14:00
Location: Ohio, USA
Contact:

Re: Help needed for a list of radio buttons

01 Aug 2014, 12:43

Good programming practice is what i was after--i could've settled for the primitive version i came up with originally which did work but presumed there was a better way.

So are these "pseudo-arrays"? AHK Help Version v1.1.15.02 says "Multidimensional arrays are possible by using a separator character of your choice between the indices." So are these 3 ways to enter the data
{Color: "&Blue", AMP: "1500mah"}
{"&Blue":"1500mah"}
["&Blue", "1500mah"]
using different delimiters: Color, AMP; or a colon? one of them does have brackets around each item rather than braces.

you don't have to write me a tutorial about objects and arrays, i'll find it. i'm pleased at the depth of AutoHotkey but dismayed that i've only scratched the surface! still, what i know has proved very useful. i have so many hotkeys programmed already that i have to keep a keyboard map!

at one point i had 3 of these loaded at the same time, on alt-f3, alt-f6, and alt-f7! i moved the Passthru battery to the bottom of the list and put the author's name--FanaticGuru, kon, toralf, and Blackholyman--in the unused AMP string to tell them apart. Thanx to all for your help!
User avatar
FanaticGuru
Posts: 1908
Joined: 30 Sep 2013, 22:25

Re: Help needed for a list of radio buttons

01 Aug 2014, 15:34

DyNama wrote:using different delimiters: Color, AMP; or a colon? one of them does have brackets around each item rather than braces.

you don't have to write me a tutorial about objects and arrays, i'll find it. i'm pleased at the depth of AutoHotkey but dismayed that i've only scratched the surface! still, what i know has proved very useful. i have so many hotkeys programmed already that i have to keep a keyboard map!
All the syntax of the {} [] "" : and such can be tricky to keep straight when assigning values to an array all in one assignment.

You can do it one element at a time though:

Code: Select all

Batteries.1.Color := "&Blue"
Batteries.1.AMP := "1500mah"
Batteries.2.Color := "&Green"
Batteries.2.AMP := "1300mah"
or

Code: Select all

Batteries["1","Color"] := "&Blue"
Batteries["1","AMP"] := "1500mah"
Batteries["2","Color"] := "&Green"
Batteries["2","AMP"] := "1300mah"
or

Code: Select all

Batteries["1","Color"] := "&Blue", Batteries["1","AMP"] := "1500mah"
Batteries["2","Color"] := "&Green", Batteries["2","AMP"] := "1300mah"
The comma just allows multiply assignments to be put on one line, like x:=1, y:=2

All the {} [] "" : are doing the same things just in a compact way.

As for the keyboard map to know what hotkeys you have assigned you might want to check out the "Hotkey Help" link in my signature. It is a script that looks for the hotkeys in all your running scripts and then takes any comments on the same line as those hotkeys to create a Hotkey Help Dialog. If you put nice uniform comments on the same line as the hotkeys in all your scripts it creates a nice looking dialog that you can pull up.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: Help needed for a list of radio buttons

01 Aug 2014, 16:12

FanaticGuru wrote:You can do it one element at a time though:

Code: Select all

Batteries.1.Color := "&Blue"
Batteries.1.AMP := "1500mah"
Batteries.2.Color := "&Green"
Batteries.2.AMP := "1300mah"
It should be noted that this will only work if Batteries.1 and Batteries.2 already contain references to objects.
i.e. If you have previously written:

Code: Select all

Batteries := {}
Batteries.1 := {}
Batteries.2 := {}
FanaticGuru wrote:or

Code: Select all

Batteries["1","Color"] := "&Blue"
Batteries["1","AMP"] := "1500mah"
Batteries["2","Color"] := "&Green"
Batteries["2","AMP"] := "1300mah"
If Batteries.1 and Batteries.2 do not already exist, this syntax will automatically create the objects and store references to them in Batteries.1 and Batteries.2.

More info.
User avatar
FanaticGuru
Posts: 1908
Joined: 30 Sep 2013, 22:25

Re: Help needed for a list of radio buttons

01 Aug 2014, 16:41

kon wrote:
FanaticGuru wrote:You can do it one element at a time though:

Code: Select all

Batteries.1.Color := "&Blue"
Batteries.1.AMP := "1500mah"
Batteries.2.Color := "&Green"
Batteries.2.AMP := "1300mah"
It should be noted that this will only work if Batteries.1 and Batteries.2 already contain references to objects.
i.e. If you have previously written:

Code: Select all

Batteries := {}
Batteries.1 := {}
Batteries.2 := {}
That is a very good point. I had problems in this area when first starting to learn AHK objects.
I generally use the [] method to put stuff into objects and the . method to get stuff out with a static name.
Like MsgBox % Customer_Database.CountDue " / " Customer_Database.CountPaid

And if I am using a dynamic variable reference to get stuff out then I use [] like:

Code: Select all

InputBox, Customer_Number, Enter Customer Number?
MsgBox % "The Customer Name on file for " Customer_Number " is "Customer_Database[Customer_Number,"Name"]
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
toralf
Posts: 868
Joined: 27 Apr 2014, 21:08
Location: Germany

Re: Help needed for a list of radio buttons

01 Aug 2014, 20:33

He also asked about pseudo arrays.

Pseudo arrays are different from what was written above. They are basically several independent variables that have a common base name and some kind of index. E.g. Array-1-1, Array-1-2, Array-1-3, Array-2-1, etc.
The "-" is the delimiter for multiple dimensions. But you can use any kind of character as long as it is not a number. With loop commands you can then go through the pseudo array. E.g. Array-%A_Index%-1 will go through one of the dimensions. To go over all fields of a two dim pseudo array you would need two nested loop commands.
ciao
toralf

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: AdsBot [Google], Google [Bot], Spawnova and 104 guests