Jump to content

Recommended Posts

Posted

Hello, i'm new to autoit and am trying to learn it since the past month. By searching this forum and examples found here have taught me a lot. I tried to make a colour box sort of thing for fun but i have come up with a problem, in my code when i click the load button the colour along with the first combobox loads up but the second combobox doesn't load. I checked the ini file and data gets saved like $dropdown2=Indian Red but it isn't being read i guess. Since the first combobox works as intented i guess the problem of the 2nd combobox lies in -setting the data after any selection is selected in the first combobox. But i'm unable to come with a solution, any help is appreciated.

#RequireAdmin
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiComboBox.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

Local $arr[5] = ["0xCD5C5C","0x800000","0xC21807","0xA45A52","0xB80F0A"]
Local $arr2[5] = ["0x000080","0x0080FF","0x008081","0x95C8D8","0x3FE0D0"]
Local $arr3[5] = ["0x00FF00","0x90EE90","0x00FF7F","0x228B22","0x8080000"]

GUICreate("Color Box",  233, 131, Default, $WS_EX_TOPMOST)

Global $box = GUICtrlCreateLabel("", 20, 20, 38, 30)
GUICtrlSetBkColor(-1,0xFFFFFF)

Local $dropdown = GUICtrlCreateCombo("", 66, 29, 70, 20)
Local $dropdown2 = GUICtrlCreateCombo("", 143, 29, 70, 20)
GUICtrlSetData($dropdown, "Red|Blue|Green" )
Local $comboread = ""
Local $comboread2 = ""

GUISetState(@SW_SHOW)

HotKeySet ("{numpad9}", "MyExit")

Global $load = GUICtrlCreateButton("LOAD",19,60,40)
Global $save = GUICtrlCreateButton("SAVE", 19,87, 40)
Global $show = GUICtrlCreateButton("SHOW COLOUR", 66, 70, 148, 34)


While 1
   $msg = GUIGetMsg()
   Select

      Case $msg = $load
         Call("Profile")

      Case $msg = $save
         Call("Save")

      Case $msg = $dropdown
         $comboread = GUICtrlRead($dropdown)
         If $comboread = "Red" Then GUICtrlSetData($dropdown2, "|Indian Red|Maroon|Chili|Redwood|Crimson" )
         If $comboread = "Blue" Then GUICtrlSetData($dropdown2, "|Navy|Azure|Teal|Sky|Turquoise" )
         If $comboread = "Green" Then GUICtrlSetData($dropdown2, "|Lime|Lightgreen|Spring|Forest|Olive" )

      Case $msg = $dropdown2
         $comboread2 = GUICtrlRead($dropdown2)
         $combosel2 = _GUICtrlComboBox_GetCurSel($dropdown2)

      Case $msg = $show
         If $comboread = "Red" Then GUICtrlSetBkColor($box,$arr[$combosel2])
         If $comboread = "Blue" Then GUICtrlSetBkColor($box,$arr2[$combosel2])
         If $comboread = "Green" Then GUICtrlSetBkColor($box,$arr3[$combosel2])

 EndSelect
WEnd

Func Profile()
   _GUICtrlComboBox_SelectString($dropdown, IniRead("Colour Box.ini","Profile 1","$dropdown",""))
   _GUICtrlComboBox_SelectString($dropdown2, IniRead("Colour Box.ini","Profile 1","$dropdown2",""))
   GUICtrlSetBkColor($box,IniRead("Colour Box.ini","Profile 1","$boxcolour",""))
EndFunc

Func Save()
   IniWrite("Colour Box.ini","Profile 1","$dropdown",GUICtrlRead($dropdown))
   IniWrite("Colour Box.ini","Profile 1","$dropdown2",GUICtrlRead($dropdown2))
   If $comboread = "Red" Then IniWrite("Colour Box.ini","Profile 1","$boxcolour",$arr[$combosel2])
   If $comboread = "Blue" Then IniWrite("Colour Box.ini","Profile 1","$boxcolour",$arr2[$combosel2])
   If $comboread = "Green" Then IniWrite("Colour Box.ini","Profile 1","$boxcolour",$arr3[$combosel2])
EndFunc

Func MyExit()
   Exit
EndFunc

 

Color Box.au3

Posted

Try the following or add it as a separate function, basically your 2nd combobox hasn't been populated so you need to populate it after loading the first combobox.

Hope that makes sense.

Func Profile()
   _GUICtrlComboBox_SelectString($dropdown, IniRead("Colour Box.ini","Profile 1","$dropdown",""))
         $comboread = GUICtrlRead($dropdown)
         If $comboread = "Red" Then GUICtrlSetData($dropdown2, "|Indian Red|Maroon|Chili|Redwood|Crimson" )
         If $comboread = "Blue" Then GUICtrlSetData($dropdown2, "|Navy|Azure|Teal|Sky|Turquoise" )
         If $comboread = "Green" Then GUICtrlSetData($dropdown2, "|Lime|Lightgreen|Spring|Forest|Olive" )
   _GUICtrlComboBox_SelectString($dropdown2, IniRead("Colour Box.ini","Profile 1","$dropdown2",""))
   GUICtrlSetBkColor($box,IniRead("Colour Box.ini","Profile 1","$boxcolour",""))
EndFunc

 

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
  • Recently Browsing   0 members

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