Jump to content
Sign in to follow this  
Lempke

Problem with two combo boxes

Recommended Posts

Lempke

I want to fill the second combobox depending on the choice made in the first combobox

Now my script stays and waits at the sleep()... did I forget something or is my script totally wrong :)

#include <Array.au3>
#include <File.au3>
#include <GuiConstants.au3>
#Include <GuiCombo.au3>

Opt("GUIOnEventMode", 1)
Opt("TrayIconDebug", 1)

Dim $MemberList1
Dim $GroupsList1

GUICreate("Combo Boxes", 320, 100)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
GUICtrlCreateGroup ("Select", 10, 10, 300, 50)

$Combo1 = GUICtrlCreateCombo("", 20, 30, 80, 20)
GUICtrlSetData(-1, "Building 1|Building 2|Building 3|Building 4|Building 5")

$Combo2 = GUICtrlCreateCombo("", 110, 30, 190, 20)
GUICtrlSetState(-1, $GUI_DISABLE)

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $Combo1
            _OU()
        Case $Combo2
            _QueryGroep()
    EndSwitch
    Sleep(50)
WEnd


Func _OU()
    $Choice1 = GUICtrlRead($Combo1, 1)
    While $Choice1 = ""
        Sleep(50)
    WEnd
    Switch $Choice1
        Case "Building 1"
            GUICtrlSetData($Combo2, "")
            GUICtrlSetData($Combo2, "Department 1a|Department 1b|Department 1c")
        Case "Building 2"
            GUICtrlSetData($Combo2, "")
            GUICtrlSetData($Combo2, "Department 2a|Department 2b|Department 2c")
        Case "Building 3"
            GUICtrlSetData($Combo2, "")
            GUICtrlSetData($Combo2, "Department 3a|Department 3b|Department 3c")
        Case "Building 4"
            GUICtrlSetData($Combo2, "")
            GUICtrlSetData($Combo2, "Department 4a|Department 4b|Department 4c")
        Case "Building 5"
            GUICtrlSetData($Combo2, "")
            GUICtrlSetData($Combo2, "Department 5a|Department 5b|Department 5c")
    EndSwitch
GUICtrlSetState($Combo2, $GUI_ENABLE)
EndFunc


Func _QueryGroup()
    _FileReadToArray(@TempDir & "\QueryGroups1.txt", $GroupsList1)
    _ArraySort($GroupsList1,"",1) 
    _ArrayDisplay($GroupsList1, "Groups")
EndFunc

Func _Quit()
    Exit
EndFunc
Edited by Lempke

Share this post


Link to post
Share on other sites
BigDod

Here is the second combo filling.

#include <Array.au3>
#include <File.au3>
#include <GuiConstants.au3>
#Include <GuiCombo.au3>

Opt("TrayIconDebug", 1)

Dim $MemberList1
Dim $GroupsList1

GUICreate("Combo Boxes", 320, 100)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
GUICtrlCreateGroup ("Select", 10, 10, 300, 50)

$Combo1 = GUICtrlCreateCombo("", 20, 30, 80, 20)
GUICtrlSetData(-1, "Building 1|Building 2|Building 3|Building 4|Building 5")

$Combo2 = GUICtrlCreateCombo("", 110, 30, 190, 20)
GUICtrlSetState(-1, $GUI_DISABLE)

GUISetState()

While 1
    $msg = GUIGetMsg()
   Select
       Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $Combo1
            _OU()
        Case $msg = $Combo2
            _QueryGroup()
    EndSelect
WEnd


Func _OU()
    $Choice1 = GUICtrlRead($Combo1, 1)
    While $Choice1 = ""
        Sleep(50)
    WEnd
    Switch $Choice1
        Case "Building 1"
             GUICtrlSetData($Combo2, "")
            GUICtrlSetData($Combo2, "Department 1a|Department 1b|Department 1c")
        Case "Building 2"
            GUICtrlSetData($Combo2, "")
            GUICtrlSetData($Combo2, "Department 2a|Department 2b|Department 2c")
        Case "Building 3"
            GUICtrlSetData($Combo2, "")
            GUICtrlSetData($Combo2, "Department 3a|Department 3b|Department 3c")
        Case "Building 4"
            GUICtrlSetData($Combo2, "")
            GUICtrlSetData($Combo2, "Department 4a|Department 4b|Department 4c")
        Case "Building 5"
            GUICtrlSetData($Combo2, "")
            GUICtrlSetData($Combo2, "Department 5a|Department 5b|Department 5c")
    EndSwitch
GUICtrlSetState($Combo2, $GUI_ENABLE)
EndFunc


Func _QueryGroup()
    _FileReadToArray(@TempDir & "\QueryGroups1.txt", $GroupsList1)
    _ArraySort($GroupsList1,"",1) 
    _ArrayDisplay($GroupsList1, "Groups")
EndFunc

Func _Quit()
    Exit
EndFunc
Edited by BigDod


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites
Lempke

Here is the second combo filling.

Is Switch...EndSwitch the problem? Why can't I use this? :)

I thought it had the same function as Select...EndSelect, but for one variable. I don't get it....

Edited by Lempke

Share this post


Link to post
Share on other sites
Lempke

Can somebody explain the problem with the Switch...EndSwitch??? I still don't get it, this should work or not???

Please somebody

Share this post


Link to post
Share on other sites
SmOke_N

You can't use GUIOnEventMode and GUIGetMsg() like you are doing.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
Lempke

You can't use GUIOnEventMode and GUIGetMsg() like you are doing.

Thx SmOke_N that was the answer I was looking for.

BigDod changed several things in my script, so I didn't know what the real problem was....and overlooked the real problem :">

Thx for clearing that up. :)

Edited by Lempke

Share this post


Link to post
Share on other sites
Valuater

this is a possible "never-ending-loop"

Func _OU()

$Choice1 = GUICtrlRead($Combo1, 1)

While $Choice1 = ""

Sleep(50)

WEnd

....better to have

Func _OU()

$Choice1 = GUICtrlRead($Combo1, 1)

If $Choice1 = "" Then Returm

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
Lempke

this is a possible "never-ending-loop"

Func _OU()

$Choice1 = GUICtrlRead($Combo1, 1)

While $Choice1 = ""

Sleep(50)

WEnd

....better to have

Func _OU()

$Choice1 = GUICtrlRead($Combo1, 1)

If $Choice1 = "" Then Returm

8)

'

Hmmm, Have to look into that then. I have put this into the script to try and solve the initial problem. I thought that the second combo had already recieved a choice before I made it in the first combo. That's why I tried that to make sure.

Share this post


Link to post
Share on other sites
Lempke

this is a possible "never-ending-loop"

Func _OU()

$Choice1 = GUICtrlRead($Combo1, 1)

While $Choice1 = ""

Sleep(50)

WEnd

It works for now, but I am keeping it in mind anyway.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.