How to get value from control Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
Coderooney
Posts: 46
Joined: 23 Mar 2017, 22:41

How to get value from control

09 Oct 2018, 09:09

The docs say the syntax is:

Code: Select all

RetrievedValue := GuiCtrl.Value
but that just gives "No object to invoke" which doesn't tell you much. What's the right way to do it? Here's essentially what I have:

Code: Select all

Gui := GuiCreate(, "Test")
Gui.Add("DropDownList", "vNato", "Alpha|Bravo|Charlie")
Gui.Add("Button", "Default", "Submit").OnEvent("Click", "onSubmit")
Gui.Show()

onSubmit() {
    letter := Nato.Value
}
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: How to get value from control  Topic is solved

09 Oct 2018, 09:30

You haven't saved the drop down list guictrl reference in a variable, look at what you did for guicreate and do the same. Furthermore, you'll have to make this saved reference accessible to your function.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: How to get value from control

09 Oct 2018, 09:40

Another way,

Code: Select all

onSubmit(btn) {
	ddl := btn.gui.control['Nato']
	msgbox ddl.Value
	msgbox ddl.Text
}
or

Code: Select all

Gui := GuiCreate(, "Test")
ddl := Gui.Add("DropDownList",, ["Alpha","Bravo","Charlie"])
Gui.Add("Button", "Default", "Submit").OnEvent("Click", func("onSubmit").bind(ddl))
Gui.Show()

onSubmit(ddl, btn) {
	msgbox ddl.Value
	msgbox ddl.Text
}
Cheers.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: How to get value from control

09 Oct 2018, 11:49

Code: Select all

btn.gui.control["Nato"]
this get parent gui, get child control method is really nice :thumbup:
User avatar
Coderooney
Posts: 46
Joined: 23 Mar 2017, 22:41

Re: How to get value from control

09 Oct 2018, 18:35

How obvious now— I was still used to vNames from V1. Thanks for pointing that out.

Code: Select all

ddl := btn.gui.control['Nato']
I tried this without "btn" earlier so thank you to for showing these options and the right way to use them!
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: How to get value from control

09 Oct 2018, 19:59

The first way that Helgef showed is why I personally think v2 GUIs are awesome. At least one reason that is.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: How to get value from control

10 Oct 2018, 01:09

The first example is good to show how things are connected, but note, in the second example, the callback doesn't need to depend on the name of the control, so it is more general. You can ofc bind the name instead of the control object. Guis are often very specific, so having the ability to name controls is probably a good idea, however, I think keeping the vName notation makes no sense.

Cheers.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Archimede, Draken, Nishanth, Panaku, RussF and 31 guests