Jump to content

Problem with two combo boxes


Lempke
 Share

Recommended Posts

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
Link to comment
Share on other sites

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


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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Moderators

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...