DropDownList OnEvent Change Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Draken
Posts: 60
Joined: 08 Dec 2022, 01:19

DropDownList OnEvent Change

22 Apr 2024, 05:01

Hello, I thought I already understood the GUI but... could someone explain me why the first script works and the second one doesn't? And how to make the second one work? Thank you.

Code: Select all

#Requires AutoHotkey 2.0

weight := ["0.0", "0.5", "0.75"]

Gui1 := Gui()
DLL1 := Gui1.AddDropDownList("x10 ym w50 choose1", weight)
DLL2 := Gui1.AddDropDownList("x+5 yp w50 choose1", weight)
Gui1.AddButton("x10 y+5 W40 h40", "OK").OnEvent("Click", OK_Click)
Gui1.Show
return

OK_Click(*){
    MsgBox weight[DLL1.Value] + weight[DLL2.Value]
}

Code: Select all

#Requires AutoHotkey 2.0

weight := ["0.0", "0.5", "0.75"]

Gui1 := Gui()
DLL1 := Gui1.AddDropDownList("x10 ym w50 choose1", weight).OnEvent("Change", OK_Click)
DLL2 := Gui1.AddDropDownList("x+5 yp w50 choose1", weight).OnEvent("Change", OK_Click)
Gui1.Show
return

OK_Click(*){
    MsgBox weight[DLL1.Value] + weight[DLL2.Value]
}
User avatar
boiler
Posts: 17285
Joined: 21 Dec 2014, 02:44

Re: DropDownList OnEvent Change  Topic is solved

22 Apr 2024, 05:12

In the second script, you didn’t assign the GuIControl objects to DLL1 and DLL2. You assigned the OnEvent method result to them. You would want to do this:

Code: Select all

#Requires AutoHotkey 2.0

weight := ["0.0", "0.5", "0.75"]

Gui1 := Gui()
DLL1 := Gui1.AddDropDownList("x10 ym w50 choose1", weight)
DLL1.OnEvent("Change", OK_Click)
DLL2 := Gui1.AddDropDownList("x+5 yp w50 choose1", weight)
DLL2.OnEvent("Change", OK_Click)
Gui1.Show
return

OK_Click(*){
    MsgBox weight[DLL1.Value] + weight[DLL2.Value]
}

Or this:

Code: Select all

#Requires AutoHotkey 2.0

weight := ["0.0", "0.5", "0.75"]

Gui1 := Gui()
Gui1.AddDropDownList("x10 ym w50 choose1 vDLL1", weight).OnEvent("Change", OK_Click)
Gui1.AddDropDownList("x+5 yp w50 choose1 vDLL2", weight).OnEvent("Change", OK_Click)
Gui1.Show
return

OK_Click(*){
    MsgBox weight[Gui1['DLL1'].Value] + weight[Gui1['DLL2'].Value]
}

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Benny-D, Rohwedder and 37 guests