huskies Posted March 13, 2009 Posted March 13, 2009 (edited) I'm making a simple gui that first you get to select "month", then you get to select day. Right now the program will only retrieve the "month" when the OK button is pressed, but I want the second drop down menu (Day) to update itself according to which month is selected without the user having to press OK So for example, if the user selects March, then the second drop down menu would have 31 days automatically, I know my code is kind of long, but I don't know a better way to deal with this issue thanks expandcollapse popup#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <GUIComboBox.au3> #include <GuiConstantsEx.au3> #include <Constants.au3> ;Calendars ;Calendars dim $Months[13] dim $Day31[32] dim $Day30[31] dim $Day28[29] $Months[0] = "Jan" $Months[1] = "Feb" $Months[2] = "Mar" $Months[3] = "Apr" $Months[4] = "May" $Months[5] = "Jun" $Months[6] = "Jul" $Months[7] = "Aug" $Months[8] = "Sep" $Months[9] = "Oct" $Months[10] = "Nov" $Months[11] = "Dec" $Months[12] = "Select Month" $Day31[0]="1" $Day31[1]="2" $Day31[2]="3" $Day31[3]="4" $Day31[4]="5" $Day31[5]="6" $Day31[6]="7" $Day31[7]="8" $Day31[8]="9" $Day31[9]="10" $Day31[10]="11" $Day31[11]="12" $Day31[12]="13" $Day31[13]="14" $Day31[14]="15" $Day31[15]="16" $Day31[16]="17" $Day31[17]="18" $Day31[18]="19" $Day31[19]="20" $Day31[20]="21" $Day31[21]="22" $Day31[22]="23" $Day31[23]="24" $Day31[24]="25" $Day31[25]="26" $Day31[26]="27" $Day31[27]="28" $Day31[28]="29" $Day31[29]="30" $Day31[30]="31" $Day31[31]="Select Day" $Day30[0]="1" $Day30[1]="2" $Day30[2]="3" $Day30[3]="4" $Day30[4]="5" $Day30[5]="6" $Day30[6]="7" $Day30[7]="8" $Day30[8]="9" $Day30[9]="10" $Day30[10]="11" $Day30[11]="12" $Day30[12]="13" $Day30[13]="14" $Day30[14]="15" $Day30[15]="16" $Day30[16]="17" $Day30[17]="18" $Day30[18]="19" $Day30[19]="20" $Day30[20]="21" $Day30[21]="22" $Day30[22]="23" $Day30[23]="24" $Day30[24]="25" $Day30[25]="26" $Day30[26]="27" $Day30[27]="28" $Day30[28]="29" $Day30[29]="30" $Day30[30]="Select Day" $Day28[0]="1" $Day28[1]="2" $Day28[2]="3" $Day28[3]="4" $Day28[4]="5" $Day28[5]="6" $Day28[6]="7" $Day28[7]="8" $Day28[8]="9" $Day28[9]="10" $Day28[10]="11" $Day28[11]="12" $Day28[12]="13" $Day28[13]="14" $Day28[14]="15" $Day28[15]="16" $Day28[16]="17" $Day28[17]="18" $Day28[18]="19" $Day28[19]="20" $Day28[20]="21" $Day28[21]="22" $Day28[22]="23" $Day28[23]="24" $Day28[24]="25" $Day28[25]="26" $Day28[26]="27" $Day28[27]="28" $Day28[28]="Select Day" $Debug_CB = False; Check ClassName being passed to ComboBox/ComboBoxEx functions, set to True and use a handle to another control to see it work dim $MonthCombo dim $DayCombo ; Create GUI GUICreate("Please select the month and day", 400, 296) $Button_1 = GUICtrlCreateButton("OK", 10, 180, 100) $MonthCombo = GUICtrlCreateCombo("", 2, 2, 396, 296) $DayCombo = GUICtrlCreateCombo("", 2, 100, 396, 296) GUICtrlSetData($DayCombo,"Select Day" & "|","Select Day") GUISetState() For $INDEX = 0 To 11 GUICtrlSetData($MonthCombo,$Months[$INDEX] & "|") Next GUICtrlSetData($MonthCombo,$Months[12] & "|",$Months[12]) GUICtrlSetFont(-1, 14, 300) ;GUISetState() ; Loop until user exits $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() If $msg = $Button_1 Then $Month = GUICtrlRead($MonthCombo) If $month = "Select Month" Then $msg = 0 else ExitLoop EndIf EndIf Wend msgbox(1,$month,$month) GUIDelete() Edited March 13, 2009 by huskies <It Shall Be Done>
Authenticity Posted March 13, 2009 Posted March 13, 2009 You don't need a button to inform your program that it's now possible to update the day combo box, just handle the $CBN_SELCHANGE notification within $WM_COMMAND notification. If don't use $CBS_SORT it's much simpler, just get the current selected index and update the day combo box.
Zedna Posted March 13, 2009 Posted March 13, 2009 expandcollapse popup;~ #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6#include <GUIComboBox.au3> #include <GuiConstantsEx.au3> #include <Constants.au3> ;Calendars ;Calendars Global $Months[13] $Months[0] = "Jan" $Months[1] = "Feb" $Months[2] = "Mar" $Months[3] = "Apr" $Months[4] = "May" $Months[5] = "Jun" $Months[6] = "Jul" $Months[7] = "Aug" $Months[8] = "Sep" $Months[9] = "Oct" $Months[10] = "Nov" $Months[11] = "Dec" $Months[12] = "Select Month" $Debug_CB = False; Check ClassName being passed to ComboBox/ComboBoxEx functions, set to True and use a handle to another control to see it work ; Create GUI GUICreate("Please select the month and day", 400, 296) $Button_1 = GUICtrlCreateButton("OK", 10, 180, 100) $MonthCombo = GUICtrlCreateCombo("", 2, 2, 396, 296) $DayCombo = GUICtrlCreateCombo("", 2, 100, 396, 296) GUICtrlSetData($DayCombo, "Select Day" & "|", "Select Day") GUISetState() For $INDEX = 0 To 11 GUICtrlSetData($MonthCombo, $Months[$INDEX] & "|") Next GUICtrlSetData($MonthCombo, $Months[12] & "|", $Months[12]) GUICtrlSetFont(-1, 14, 300) ;GUISetState() Global $Month Global $Day ; Loop until user exits $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() If $msg = $MonthCombo Then $Month = GUICtrlRead($MonthCombo) Switch $Month Case "Jan", "Mar", "May" ; ... FilterDay(31) Case "Apr", "Jun" ; ... FilterDay(30) Case "Feb" FilterDay(28) EndSwitch EndIf If $msg = $Button_1 Then $Month = GUICtrlRead($MonthCombo) $Day = GUICtrlRead($DayCombo) If $Month <> "Select Month" And $Day <> "Select Day" Then ExitLoop EndIf EndIf WEnd MsgBox(1, $Month, $Day) GUIDelete() Func FilterDay($NumDays) GUICtrlSetData($DayCombo, "") For $INDEX = 1 To $NumDays GUICtrlSetData($DayCombo, $INDEX & "|") Next GUICtrlSetData($DayCombo, "Select Day", "Select Day") EndFunc Resources UDF ResourcesEx UDF AutoIt Forum Search
huskies Posted March 13, 2009 Author Posted March 13, 2009 @Zedna, thank you very much ! One additional question, Do you know how I can change the font of the First drop down menu so that they are the same size? how come that I have GUICtrlSetFont(-1, 14, 300) yet the first drop down menu is still so small compared to the second one when the code is telling it to be font 14? <It Shall Be Done>
PhilRip Posted March 13, 2009 Posted March 13, 2009 GUICtrlSetFont($MonthCombo, 14, 300) GUICtrlSetFont($DayCombo, 14, 300)
Zedna Posted March 13, 2009 Posted March 13, 2009 (edited) @Zedna, thank you very much ! One additional question, Do you know how I can change the font of the First drop down menu so that they are the same size? how come that I have GUICtrlSetFont(-1, 14, 300) yet the first drop down menu is still so small compared to the second one when the code is telling it to be font 14? ... $MonthCombo = GUICtrlCreateCombo("", 2, 2, 396, 296) GUICtrlSetFont(-1, 14, 300) $DayCombo = GUICtrlCreateCombo("", 2, 100, 396, 296) GUICtrlSetFont(-1, 14, 300) ... Edited March 13, 2009 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now