Enumerating and accessing a very simple object Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
ItisI
Posts: 56
Joined: 03 Jul 2023, 11:50

Enumerating and accessing a very simple object

Post by ItisI » 25 Aug 2023, 09:00

(after clicking "New Topic" I got this message in red
"The submitted form was invalid. Try submitting again.")

I'm lost - I've tried different topics in the doc, tried a search, can't seem to understand the explanations. The examples given are way above my pay grade.

I have created (successfully) the following object:

Code: Select all

newNumMonth := {
    January: "01",
    February: "02",
    March: "03",
    April: "04",
    May: "05",
    June: "06",
    July: "07",
    August: "08",
    September: "09",
    October: "10",
    November: "11",
    December: "12"
}
I can access
'newNumMonth.October'

but I don't know

1. how to check for a possible property, say look for  "May"
2. Nor can I enumerate the object to see what's in it.

Please help :)
User avatar
mikeyww
Posts: 27216
Joined: 09 Sep 2014, 18:38

Re: Enumerating and accessing a very simple object

Post by mikeyww » 25 Aug 2023, 09:13

You are posting in the v2 forum. See documentation for For and HasKey.

EDIT: OK for v2.
Last edited by mikeyww on 25 Aug 2023, 09:14, edited 1 time in total.
User avatar
ItisI
Posts: 56
Joined: 03 Jul 2023, 11:50

Re: Enumerating and accessing a very simple object

Post by ItisI » 25 Aug 2023, 09:13

Found (1.) - by accident:

Code: Select all

MsgBox newNumMonth.HasProp("June")
Windows 10 - AutoHotkey 2.0.3 - VSCode - AutoHotkey v2 Language Support - vscode-autohotkey-debug

2b || !2b

User avatar
mikeyww
Posts: 27216
Joined: 09 Sep 2014, 18:38

Re: Enumerating and accessing a very simple object  Topic is solved

Post by mikeyww » 25 Aug 2023, 09:17

Code: Select all

For month, monthNum in newNumMonth.OwnProps()
 MsgBox month ': ' monthNum
Explained: OwnProps
User avatar
ItisI
Posts: 56
Joined: 03 Jul 2023, 11:50

Re: Enumerating and accessing a very simple object

Post by ItisI » 25 Aug 2023, 09:22

@mikeyww - I am still on v2 - my scripts are progressing well and, sir, I don't know what you do, but I swear I checked out the very page and now
This suddenly works?

Code: Select all

newNumMonth := {
    January: "01",
    February: "02",
    March: "03",
    April: "04",
    May: "05",
    June: "06",
    July: "07",
    August: "08",
    September: "09",
    October: "10",
    November: "11",
    December: "12"
}

s := ""
for k, v in newNumMonth.OwnProps()
    s .= k "=" v "`n"
MsgBox s
Thanks a lot!
Windows 10 - AutoHotkey 2.0.3 - VSCode - AutoHotkey v2 Language Support - vscode-autohotkey-debug

2b || !2b

User avatar
ItisI
Posts: 56
Joined: 03 Jul 2023, 11:50

Re: Enumerating and accessing a very simple object

Post by ItisI » 25 Aug 2023, 09:26

And with your version:

Code: Select all

#Requires AutoHotkey v2.0
#Include "udf.ahk"
#Include "UDF-test.ahk"
(edit 2023-08-25 16:28:31)

newNumMonth := {
    January: "01",
    February: "02",
    March: "03",
    April: "04",
    May: "05",
    June: "06",
    July: "07",
    August: "08",
    September: "09",
    October: "10",
    November: "11",
    December: "12"
}
/*--------------------------------------------------------------

s := ""
for k, v in newNumMonth.OwnProps()
    s .= k "=" v "`n"
MsgBox s

--------------------------------------------------------------*/
For month, monthNum in newNumMonth.OwnProps()
    MsgBox month ': ' monthNum
Much obliged :D
Windows 10 - AutoHotkey 2.0.3 - VSCode - AutoHotkey v2 Language Support - vscode-autohotkey-debug

2b || !2b

Post Reply

Return to “Ask for Help (v2)”