Variable from ListBox

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
rogerrabbitthefirst
Posts: 9
Joined: 12 Mar 2016, 05:08

Variable from ListBox

12 Mar 2016, 05:27

I am trying to send input from ListBoxes using variables, but instead of just sending my ListBox selections (total of 3 digits, one from each of the 3 ListBoxes) it sends all the ListBox entries (total of 30 digits). I have been trying for days to get this to work without success. I have checked the help regarding ListBoxes and Variables.
Can anyone point me in the right direction to make the "if" code work please?

Code: Select all

Gui, Add, ListBox, r10 vMyListBox1 gMyListBox1, 1st|2nd|3nd|4th|5th|6th|7th|8th|9th|10th
Gui, 2:Add, ListBox, r10 vMyListBox2 gMyListBox2, 1st|2nd|3nd|4th|5th|6th|7th|8th|9th|10th
Gui, 3:Add, ListBox, r10 vMyListBox3 gMyListBox3, 1st|2nd|3nd|4th|5th|6th|7th|8th|9th|10th
Gui, +AlwaysOnTop

Gui, Show
return

MyListBox1:
if A_GuiControlEvent <> Normal
    return
GuiControlGet, MyListBox1  ; Retrieve the ListBox's current selection.
Gui, Destroy
Gui, 2:Show 
return

MyListBox2:
if A_GuiControlEvent <> Normal
    return
GuiControlGet, MyListBox2  ; Retrieve the ListBox's current selection.
Gui, 2:Destroy
Gui, 3:Show 
return

MyListBox3:
if A_GuiControlEvent <> Normal
    return
GuiControlGet, MyListBox3  ; Retrieve the ListBox's current selection.

Send, !{Esc}
Sleep, 200

if (%MyListBox1%=1st)
	SendInput, a
if (%MyListBox1%=2nd)
	SendInput, b
if (%MyListBox1%=3rd)
	SendInput, c
if (%MyListBox1%=4th)
	SendInput, d
if (%MyListBox1%=5th)
	SendInput, e
if (%MyListBox1%=6th)
	SendInput, f
if (%MyListBox1%=7th)
	SendInput, g
if (%MyListBox1%=8th)
	SendInput, h
if (%MyListBox1%=9th)
	SendInput, i
if (%MyListBox2%=10th)
	SendInput, j
if (%MyListBox2%=1st)
	SendInput, a
if (%MyListBox2%=2nd)
	SendInput, b
if (%MyListBox2%=3rd)
	SendInput, c
if (%MyListBox2%=4th)
	SendInput, d
if (%MyListBox2%=5th)
	SendInput, e
if (%MyListBox2%=6th)
	SendInput, f
if (%MyListBox2%=7th)
	SendInput, g
if (%MyListBox2%=8th)
	SendInput, h
if (%MyListBox2%=9th)
	SendInput, i
if (%MyListBox2%=10th)
	SendInput, j
    if (%MyListBox3%=1st)
	SendInput, a
if (%MyListBox3%=2nd)
	SendInput, b
if (%MyListBox3%=3rd)
	SendInput, c
if (%MyListBox3%=4th)
	SendInput, d
if (%MyListBox3%=5th)
	SendInput, e
if (%MyListBox3%=6th)
	SendInput, f
if (%MyListBox3%=7th)
	SendInput, g
if (%MyListBox3%=8th)
	SendInput, h
if (%MyListBox3%=9th)
	SendInput, i
if (%MyListBox3%=10th)
	SendInput, j 
    
Gui, 3:Destroy
return 
    
ExitApp
return
Thank you if anyone can assist!
Roger
Submit

Re: Variable from ListBox

12 Mar 2016, 07:16

Two things I can see at the moment.

First, you can replace your GuiControlGet + Gui, Destroy with one command which is easier Gui, Submit, Destroy the selected item is now in the variable you've defined

Second, you've made a mistake in your if () it should be if (MyListBox1 = "1st") or if %MyListBox1% = 1st - if you use the expression mode by using () you don't need to wrap your variables in %% and the contents you want to check needs to be wrapped in "" or omit the () and thus not use expression mode. (search the documentation for expression)
rogerrabbitthefirst
Posts: 9
Joined: 12 Mar 2016, 05:08

Re: Variable from ListBox

12 Mar 2016, 08:13

Now working - thank you very much!
Roger

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, Google [Bot] and 121 guests