Dynamic Variable output in textbox

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
agags333
Posts: 13
Joined: 25 Apr 2017, 23:50

Dynamic Variable output in textbox

30 Apr 2017, 18:49

Hi Gurus
Not sure what im doing wrong, as i am new to AHK or programming for that matter
but im trying to output one variable based on the selection of another

Code: Select all

#SingleInstance Force

Var1= || Test1| Test2| Test3|
if Var1 = Test1
	Var2 = A
If Var1 = Test2
	Var2 = B
Else if Var1 = Test3
	Var2 = C

Gui Add, DropDownList, x20 y20 w200 vMyDDL gVar1, %Var1%
Gui Add, Text, w220 h20 vVar2

Gui Show
Return

GuiEscape:
ExitApp

Var1:
GuiControlGet, Var1
GuiControl,, edit1 %edit1%
Return
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Dynamic Variable output in textbox

30 Apr 2017, 19:25

I'm not sure if I understand your intention correctly. Try this:

Code: Select all

#SingleInstance Force

Var1 = || Test1| Test2| Test3|
Gui Add, DropDownList, x20 y20 w200 vMyDDL gVar1, %Var1%
Gui Add, Text, w220 h20 vVar2
Gui Show
Return

GuiEscape:
ExitApp

Var1:
    GuiControlGet, MyDDL
    GuiControl,, Static1, %MyDDL%
Return
I hope that helps.
agags333
Posts: 13
Joined: 25 Apr 2017, 23:50

Re: Dynamic Variable output in textbox

30 Apr 2017, 19:29

Thank you, however my intention is to have text box show something else based on what is chosen in Dropdown list
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Dynamic Variable output in textbox

30 Apr 2017, 19:32

This may get closer? Try this:

Code: Select all

#SingleInstance Force

Var1 = Test1|Test2|Test3
Gui Add, DropDownList, x20 y20 w200 vMyDDL gVar1, %Var1%
Gui Add, Text, w220 h20 vVar2
Gui Show
Return

GuiEscape:
ExitApp

Var1:
    GuiControlGet, MyDDL
    If (MyDDL = "Test1")
        Display := "A"
    Else If (MyDDL = "Test2")
        Display := "B"
    Else If (MyDDL = "Test3")
        Display := "C"
    GuiControl,, Static1, %Display%
Return
I hope that helps.
agags333
Posts: 13
Joined: 25 Apr 2017, 23:50

Re: Dynamic Variable output in textbox

30 Apr 2017, 19:34

Your a Gun
thank you!
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Dynamic Variable output in textbox

30 Apr 2017, 19:39

You can also use an associative array. I commented the code. Uncomment the msgboxes to figure it out if it is not intuitive at first sight.

Code: Select all

#SingleInstance Force

myObject := {"test1": "A", "test2": "B", "test3": "C"} ; associative array
; MsgBox % myObject["test1"]
; MsgBox % myObject["test2"]
; MsgBox % myObject["test3"]

dropDownListChoices := "" ; empty string
choice := "test2" ; the default choice for the DDL

for key, value in myObject ; repeats a series of commands once for each key-value pair in myObject.
{
	if (key == choice)
	dropDownListChoices .= key . "||"
	else
	dropDownListChoices .= key . "|"
} ; a simple DDL pipe-delimited list of choices builder
; MsgBox % dropDownListChoices

Gui Add, DropDownList, x20 y20 w200 vMyDDL glabel, %dropDownListChoices%
Gui Add, Text, w220 h20 vMyEdit,
Gui Show
Return

GuiEscape:
ExitApp

label:
; MsgBox % A_GuiControl
GuiControlGet, userChoice,, %A_GuiControl% ; A_GuiControl contents the name of the variable associated with the GUI control that launched the current thread (MyDDL)
; MsgBox % userChoice
GuiControl,, MyEdit, % myObject[userChoice] ; get myObject userChoice-key value
Return

Hope this helps.
my scripts
agags333
Posts: 13
Joined: 25 Apr 2017, 23:50

Re: Dynamic Variable output in textbox

30 Apr 2017, 19:46

Thats boss, thank you very much, ill nut it out and manipulate, i really appreciate your help

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Rohwedder and 116 guests