marko001 Posted May 31, 2011 Share Posted May 31, 2011 (edited) Hi all,here is the starting code:expandcollapse popup#include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= GUICreate("Form1", 551, 115, 192, 124) $combo = GUICtrlCreateCombo("", 8, 16, 65, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) GUICtrlSetData(-1,"Stock1|Stock2|Stock3|Stock4|") $Qty = GUICtrlCreateInput("", 80, 16, 121, 21) GUICtrlSetState(-1,$GUI_DISABLE) $Min = GUICtrlCreateInput("", 208, 16, 121, 21) GUICtrlSetState(-1,$GUI_DISABLE) $Max = GUICtrlCreateInput("", 336, 16, 121, 21) GUICtrlSetState(-1,$GUI_DISABLE) $Notes = GUICtrlCreateEdit("", 80, 40, 377, 57) GUICtrlSetState(-1,$GUI_DISABLE) $Update = GUICtrlCreateButton("Update", 464, 16, 75, 25) GUICtrlSetState(-1,$GUI_DISABLE) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 _Active_only_if_selected() $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd func _Active_only_if_selected() if GUICtrlRead($combo) <> "" And BitAND( GUICtrlGetState($Qty),$GUI_DISABLE) = $GUI_DISABLE Then GUICtrlSetState($Qty,$gui_enable) if GUICtrlRead($Qty) <> "" And BitAND( GUICtrlGetState($Min),$GUI_DISABLE) = $GUI_DISABLE Then GUICtrlSetState($Min,$gui_enable) if GUICtrlRead($Min) <> "" And BitAND( GUICtrlGetState($Max),$GUI_DISABLE) = $GUI_DISABLE Then GUICtrlSetState($Max,$gui_enable) if GUICtrlRead($Max) <> "" And BitAND( GUICtrlGetState($Notes),$GUI_DISABLE) = $GUI_DISABLE Then GUICtrlSetState($Notes,$gui_enable) if GUICtrlRead($Notes) <> "" And BitAND( GUICtrlGetState($Update),$GUI_DISABLE) = $GUI_DISABLE Then GUICtrlSetState($Update,$gui_enable) EndFuncNow the program enables the inputboxes once a value in combo is selected. DoneOnce "Update" is pressed i'm going to save datas in a setting.ini file. Done[Stock1] Quantity=100 Min =1 Max =20 Notes =Bestbuy [Stock2] Quantity=30 Min =4 Max =15 Notes =Spin . . .What I'm missing, and I'm just returning an infinite loop that doesn't solve the problem is:When I load the gui I need, once a Combo value is choosen, to auto-fill the input datas if in settings.ini the data is already stored (but I need to have possibility to modify datas trough the inputs)I didfunc _check() if GUICtrlRead($combo) = "Stock1" Then GUICtrlSetData($qty, $s_qty1)) if GUICtrlRead($combo) = "Stock1" Then GUICtrlSetData($min, $s_min1)) if GUICtrlRead($combo) = "Stock1" Then GUICtrlSetData($max, $s_max1)) and so on fot Stock2,3 endfuncIf I put the _check() inside the While routine he correctly puts datas in the inputboxes but doesn't let me modify them anymore (since the loop continues forever)$s_qty1 is given by :IniWrite(@ScriptDir & "\Settings.ini", "Stock1","Quantity", GUICtrlRead($qty))How can I manage it? Edited June 1, 2011 by marko001 Link to comment Share on other sites More sharing options...
ahmet Posted May 31, 2011 Share Posted May 31, 2011 (edited) Put this in your switch statement Case $combo If BitAND(GUICtrlGetState($Qty), $GUI_DISABLE) = $GUI_DISABLE Then GUICtrlSetState($Qty, $gui_enable) ElseIf GUICtrlRead($Qty)="" And BitAND(GUICtrlGetState($Qty), $GUI_Enable) = $gui_enable Then GUICtrlSetState($Qty, $GUI_DISABLE) EndIf and remove first line from _Active_only_if_selected() function. Edited May 31, 2011 by ahmet Link to comment Share on other sites More sharing options...
marko001 Posted June 1, 2011 Author Share Posted June 1, 2011 Here is the full script, including the _save and _loadsettings() It doesn't work, try to run and look where it loops. You can remove the "for" cycle inside the function to let it work fine, but it doesn't solve. expandcollapse popupinclude <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $settings = @ScriptDir & "\settings2.ini" #Region ### START Koda GUI section ### Form= GUICreate("Form1", 551, 115, 192, 124) $combo = GUICtrlCreateCombo("", 8, 16, 65, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) GUICtrlSetData(-1,"Stock1|Stock2|Stock3|Stock4|") $Qty = GUICtrlCreateInput("", 80, 16, 121, 21) GUICtrlSetState(-1,$GUI_DISABLE) $Min = GUICtrlCreateInput("", 208, 16, 121, 21) GUICtrlSetState(-1,$GUI_DISABLE) $Max = GUICtrlCreateInput("", 336, 16, 121, 21) GUICtrlSetState(-1,$GUI_DISABLE) $Notes = GUICtrlCreateEdit("", 80, 40, 377, 57) GUICtrlSetState(-1,$GUI_DISABLE) $Update = GUICtrlCreateButton("Update", 464, 16, 75, 25) GUICtrlSetState(-1,$GUI_DISABLE) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### _loadsettings() While 1 _Active_only_if_selected() $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $combo If BitAND(GUICtrlGetState($Qty), $GUI_DISABLE) = $GUI_DISABLE Then GUICtrlSetState($Qty, $gui_enable) ElseIf GUICtrlRead($Qty)="" And BitAND(GUICtrlGetState($Qty), $GUI_Enable) = $gui_enable Then GUICtrlSetState($Qty, $GUI_DISABLE) EndIf case $Update _savesettings(GUICtrlRead($combo)) EndSwitch WEnd func _Active_only_if_selected() ;if GUICtrlRead($combo) <> "" And BitAND( GUICtrlGetState($Qty),$GUI_DISABLE) = $GUI_DISABLE Then GUICtrlSetState($Qty,$gui_enable) if GUICtrlRead($Qty) <> "" And BitAND( GUICtrlGetState($Min),$GUI_DISABLE) = $GUI_DISABLE Then GUICtrlSetState($Min,$gui_enable) if GUICtrlRead($Min) <> "" And BitAND( GUICtrlGetState($Max),$GUI_DISABLE) = $GUI_DISABLE Then GUICtrlSetState($Max,$gui_enable) if GUICtrlRead($Max) <> "" And BitAND( GUICtrlGetState($Notes),$GUI_DISABLE) = $GUI_DISABLE Then GUICtrlSetState($Notes,$gui_enable) if GUICtrlRead($Notes) <> "" And BitAND( GUICtrlGetState($Update),$GUI_DISABLE) = $GUI_DISABLE Then GUICtrlSetState($Update,$gui_enable) for $i = 1 to 4 local $s Assign("s","Stock" & $i) if GUICtrlRead($combo) = $s Then GUICtrlSetData($Qty,eval("s_Stock" & $i & "_Qty")) if GUICtrlRead($combo) = $s Then GUICtrlSetData($Min,eval("s_Stock" & $i & "_Min")) if GUICtrlRead($combo) = $s Then GUICtrlSetData($Max,eval("s_Stock" & $i & "_Max")) if GUICtrlRead($combo) = $s Then GUICtrlSetData($Notes,eval("s_Stock" & $i & "_Notes")) Next EndFunc Func _loadsettings() $S_Stock1_Qty = IniRead(@ScriptDir & "\Settings2.ini", "Stock1", "Quantity","") $S_Stock2_Qty = IniRead(@ScriptDir & "\Settings2.ini", "Stock2", "Quantity","") $S_Stock3_Qty = IniRead(@ScriptDir & "\Settings2.ini", "Stock3", "Quantity","") $S_Stock4_Qty = IniRead(@ScriptDir & "\Settings2.ini", "Stock4", "Quantity","") $S_Stock1_Min = IniRead(@ScriptDir & "\Settings2.ini", "Stock1", "Min","") $S_Stock2_Min = IniRead(@ScriptDir & "\Settings2.ini", "Stock2", "Min","") $S_Stock3_Min = IniRead(@ScriptDir & "\Settings2.ini", "Stock3", "Min","") $S_Stock4_Min = IniRead(@ScriptDir & "\Settings2.ini", "Stock4", "Min","") $S_Stock1_Max = IniRead(@ScriptDir & "\Settings2.ini", "Stock1", "Max","") $S_Stock2_Max = IniRead(@ScriptDir & "\Settings2.ini", "Stock2", "Max","") $S_Stock3_Max = IniRead(@ScriptDir & "\Settings2.ini", "Stock3", "Max","") $S_Stock4_Max = IniRead(@ScriptDir & "\Settings2.ini", "Stock4", "Max","") $S_Stock1_Notes = IniRead(@ScriptDir & "\Settings2.ini", "Stock1", "Notes","") $S_Stock2_Notes = IniRead(@ScriptDir & "\Settings2.ini", "Stock2", "Notes","") $S_Stock3_Notes = IniRead(@ScriptDir & "\Settings2.ini", "Stock3", "Notes","") $S_Stock4_Notes = IniRead(@ScriptDir & "\Settings2.ini", "Stock4", "Notes","") EndFunc Func _savesettings($i) $i = StringTrimLeft($i,5) IniWrite(@ScriptDir & "\Settings2.ini", "Stock" & $i,"Quantity", GUICtrlRead($Qty)) IniWrite(@ScriptDir & "\Settings2.ini", "Stock" & $i,"Min", GUICtrlRead($Min)) IniWrite(@ScriptDir & "\Settings2.ini", "Stock" & $i,"Max", GUICtrlRead($Max)) IniWrite(@ScriptDir & "\Settings2.ini", "Stock" & $i,"Notes", GUICtrlRead($Notes)) EndFunc Link to comment Share on other sites More sharing options...
ahmet Posted June 1, 2011 Share Posted June 1, 2011 First you have to make variables inside functions global, otherwise eval("s_Stock" & $i & "_Qty") fails.Try to avoid updates in while loop. Put this Case $combo If BitAND(GUICtrlGetState($Qty), $GUI_DISABLE) = $GUI_DISABLE Then GUICtrlSetState($Qty, $gui_enable) ElseIf GUICtrlRead($Qty)="" And BitAND(GUICtrlGetState($Qty), $GUI_Enable) = $gui_enable Then GUICtrlSetState($Qty, $GUI_DISABLE) EndIf $i=StringRight(GUICtrlRead($combo),1) GUICtrlSetData($Qty,Eval("s_Stock" & $i & "_Qty")) GUICtrlSetData($Min,eval("s_Stock" & $i & "_Min")) GUICtrlSetData($Max,eval("s_Stock" & $i & "_Max")) GUICtrlSetData($Notes,eval("s_Stock" & $i & "_Notes")) an remove for loop from _Active_only_if_selected() function. The code doesn' always enables\disables input controls as it should. Link to comment Share on other sites More sharing options...
marko001 Posted June 1, 2011 Author Share Posted June 1, 2011 (edited) Works perfectly. Just one hint, it's necessary to add in "case $update..." also a "loadsettings()" so the inputboxes are relaoded correctly. I'll post the full code as example for future useTest_combo_3.au3 Edited June 1, 2011 by marko001 Link to comment Share on other sites More sharing options...
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