GUI

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
arathra
Posts: 23
Joined: 29 Aug 2016, 06:22

GUI

11 Jul 2018, 06:53

Hi - I hope someone can help. I have a functioning script but it seems very clumsy to me and I'm sure there's a far better way of writing it.

Basically I have a GUI which presents a number of buttons, each of which is the name of a country. It looks something like this (in the actual version there are loads more options).

Code: Select all

	Gui, Add, Button, w120 h40 gAlbania, Albania
	Gui, Add, Button, w120 h40 gAustria, Austria
	Gui, Add, Button, w120 h40 gBelgium, Belgium
	Gui, Add, Button, w120 h40 gBulgaria, Bulgaria
	Gui, Add, Button, w120 h40 gCyprus, Cyprus
	Gui, Add, Button, w120 h40 gCzechia, Czechia
	Gui, Show
	Return
And at the moment under the GUI code I have this:

Code: Select all

	Albania:
		DoUrl( "Albania" )
	Austria:
		DoUrl( "Austria" )
	Belgium:
		DoUrl( "Belgium" )
	Bulgaria:
		DoUrl( "Bulgaria" )
	Czechia: 
		DoUrl( "Czechia" )
It simply gets the value of the button and passes it to a function, DoUrl.

But this seems very clumsy to me. Is there a simpler way of doing this? Can I have a small snippet which will take the name of the button clicked and send that straight away to the DoUrl function?

Any suggestions more than welcome!
digidings
Posts: 24
Joined: 22 Jan 2018, 17:04

Re: GUI

11 Jul 2018, 07:54

Hi, you might try this ...

Code: Select all

#SingleInstance, force
#NoEnv
    countries := ["Albania", "Austria", "Belgium"
                ; add more countries here ...
                , "Zimbabwe"]
    for a,country in countries {
        Gui, add, Button, w120 h40 vBt_%country% gCheckCountry, % country
    }
    Gui show
    return

CheckCountry:
    ; which Gui-Element has fired ? e.g. Bt_Austria
    country := SubStr(A_GuiControl, 4)
    DoUrl(country)
    return
    
DoUrl(theCountry) {
        MsgBox % "your selection: " . theCountry
}        
    
Last edited by digidings on 11 Jul 2018, 08:21, edited 1 time in total.
GEV
Posts: 1005
Joined: 25 Feb 2014, 00:50

Re: GUI

11 Jul 2018, 08:05

Code: Select all

Gui, Add, Button, w120 h40 gCountry, Albania
Gui, Add, Button, w120 h40 gCountry, Austria
Gui, Add, Button, w120 h40 gCountry, Belgium
Gui, Add, Button, w120 h40 gCountry, Bulgaria
Gui, Add, Button, w120 h40 gCountry, Cyprus
Gui, Add, Button, w120 h40 gCountry, Czechia
Gui, Show
Return

Country:
Gui, Submit, NoHide
OutputVar := A_GuiControl
DoUrl(OutputVar)
return

DoUrl(OutputVar){
MsgBox, "%OutputVar%"
}
arathra
Posts: 23
Joined: 29 Aug 2016, 06:22

Re: GUI

11 Jul 2018, 08:15

Thank you very much indeed for that.

In the end I went for this one:

Code: Select all

...
Gui, Add, Button, w120 h40 gCheckCountry, Poland
...

CheckCountry:
country := A_GuiControl
DoUrl( country )
Again, thanks to you both for the suggestions.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 376 guests