Gerry Posted December 2, 2008 Share Posted December 2, 2008 Hi Everyone I am writting a script to do costingfrom an Excel speadsheet. I need to bill the client for a few items, mainly PC's, monitors and printers. I have lists of prices which I'll put in to a .ini file. My problem is that there is a lot of checkboxes which I need to update or clear when going to the next transaction. Transactions are read from a common spreadsheet. No problems here. I have a code simmular to this, just plenty ore lines Func _Clear() GuiCtrlSetState($Checkbox1, $GUI_UNCHECKED) GuiCtrlSetState($Checkbox2, $GUI_UNCHECKED) GuiCtrlSetState($Checkbox3, $GUI_UNCHECKED) EndFunc It works fine but nfortunately there is a lot of checkboxes and it means a lot of repetative entries. Since the checkboxnames only vary from each other by the last number, I was hoping to something like this: Func _Clear() For $i = 1 to 80 GuiCtrlSetState("$Checkbox" & $i, $GUI_UNCHECKED) Next EndFunc Is this possible or will I have to have a code line for each checkbox? Thanks for any assistance or suggestions. Gerry Link to comment Share on other sites More sharing options...
Zedna Posted December 2, 2008 Share Posted December 2, 2008 Func _Clear()For $i = 1 to 80 GuiCtrlSetState(Eval("$Checkbox" & $i), $GUI_UNCHECKED) Next EndFunc Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Gerry Posted December 2, 2008 Author Share Posted December 2, 2008 Func _Clear()For $i = 1 to 80 GuiCtrlSetState(Eval("$Checkbox" & $i), $GUI_UNCHECKED) Next EndFunc Hi Hope this comes out ok, my 1st time to reply here Thanks for your response I tried your suggestion but it did not work, I then added a messagebox to try and debug it like this: For $i = 1 to 10 GuiCtrlSetState(Eval("$Checkbox" & $i), $GUI_UNCHECKED) MsgBox(0,"checkbox", Eval("$Checkbox" & $i)) Next Even the mesagebox is empty . . . . Any ideas Gerry Link to comment Share on other sites More sharing options...
rasim Posted December 2, 2008 Share Posted December 2, 2008 GerryCreate a array with checkboxes and do check/uncheck checkboxes in a loop. Link to comment Share on other sites More sharing options...
Gerry Posted December 2, 2008 Author Share Posted December 2, 2008 GerryCreate a array with checkboxes and do check/uncheck checkboxes in a loop.Hi Thanks for everyone responses, but as a amateur I think I'm in over my head, I think I must stick to the lengthy code of repeating the 80 lines of repeated code. I understand very little of arrays and to work out a useful code with that is just above me at this stage. Thanks anyhowGerry Link to comment Share on other sites More sharing options...
Zedna Posted December 2, 2008 Share Posted December 2, 2008 (edited) I had a bug in my example. Try this (Eval without $): Func _Clear() For $i = 1 to 80 GuiCtrlSetState(Eval("Checkbox" & $i), $GUI_UNCHECKED) Next EndFunc Edited December 2, 2008 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Malkey Posted December 2, 2008 Share Posted December 2, 2008 (edited) Hi Thanks for everyone responses, but as a amateur I think I'm in over my head, I think I must stick to the lengthy code of repeating the 80 lines of repeated code. I understand very little of arrays and to work out a useful code with that is just above me at this stage. Thanks anyhow GerryThis example works on xp. From one amateur to another - Enjoy expandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> CheckBoxes() Func CheckBoxes() Local $ChkBxForm = GUICreate("Check Box Form", 660, 331, 194, 516, -1, $WS_EX_TOPMOST) GUISetBkColor(0xf0f0FF, $ChkBxForm) Local $NoChkBx = 80 ; Max 180 Local $NoPerRow = 20 ; Max 30 Local $aCheckBoxes[$NoChkBx + 1] Local $ChkBxSelect, $iSetX = 60, $iSetY = 25 GUICtrlCreateLabel("Multi-Select Checkbox", 200, $iSetY - 20) ;Create CheckBoxes and their Labels GUICtrlCreateLabel("Point Nos", 5, $iSetY) For $x = 1 To $NoChkBx GUICtrlCreateLabel($x, $iSetX, $iSetY) $aCheckBoxes[$x] = GUICtrlCreateCheckbox("", $iSetX, $iSetY + 15) $iSetX += 20 If Mod($x, $NoPerRow) = 0 Then $iSetY += 43 $iSetX = 60 If $NoChkBx - $x > 0 Then GUICtrlCreateLabel("Point Nos", 5, $iSetY) EndIf Next ; Create five Buttons Dim $aButtons[2][5] = [[0, 0, 0, 0, 0],["Checked List", "Select All", "Select Every 2nd", "Flip All", "Finish"]] $iSetX = 20 $iSetY = 290 For $x = 0 To 4 $aButtons[0][$x] = GUICtrlCreateButton($aButtons[1][$x], $iSetX, $iSetY, 100) $iSetX += 130 Next GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case - 3, $aButtons[0][4] ExitLoop Case $aButtons[0][0] ; List all Check boxes cheched For $x = 1 To $NoChkBx If GUICtrlRead($aCheckBoxes[$x]) = 1 Then $ChkBxSelect &= $x & " " Next ; One way of listing results Local $res = StringRegExpReplace($ChkBxSelect, "(\S+)", "$aCheckBoxes[\0]" & @CRLF) ConsoleWrite("CheckBox handles selected are " & @CRLF & $res & @CRLF) $res = "" ; Another way of listing results Local $result = StringRegExp($ChkBxSelect, "(\S+)", 3) For $x = 0 To UBound($result) - 1 $res &= "$result[" & $x & "] = " & $result[$x] & @CRLF Next MsgBox(0, "Is Array", $res, 0, $ChkBxForm) $res = "" $ChkBxSelect = "" Case $aButtons[0][1] ; Select All For $x = 1 To $NoChkBx GUICtrlSetState($aCheckBoxes[$x], 1) ; From /Include/GuiConstantsEx.au3 Global Const $GUI_CHECKED = 1 Next Case $aButtons[0][2] ; Select Every 2nd For $x = 1 To $NoChkBx Step 2 GUICtrlSetState($aCheckBoxes[$x], 1) ; From /Include/GuiConstantsEx.au3 Global Const $GUI_CHECKED = 1 Next Case $aButtons[0][3] ; Flip All For $x = 1 To $NoChkBx If GUICtrlRead($aCheckBoxes[$x]) = 1 Then GUICtrlSetState($aCheckBoxes[$x], 4) ; From /Include/GuiConstantsEx.au3 Global Const $GUI_UNCHECKED = 4 Else GUICtrlSetState($aCheckBoxes[$x], 1) ; From /Include/GuiConstantsEx.au3 Global Const $GUI_CHECKED = 1 EndIf Next EndSwitch WEnd Return EndFunc ;==>CheckBoxes Edited December 2, 2008 by Malkey Link to comment Share on other sites More sharing options...
Gerry Posted December 2, 2008 Author Share Posted December 2, 2008 Hi Malkey Wow I did not expect you to do this for me! Thanks!! Just creating my initial Gui has more lines than your whole script . . . . If you are an amateur then I must definitely be the appy's appy! Your script works very nice on my XP too, and 20K plus script should now be much smaller and neater, thanks again buddy. Gerry Link to comment Share on other sites More sharing options...
Gerry Posted December 2, 2008 Author Share Posted December 2, 2008 Hi Zedna Sorry missed your reply, I have just tried the "Eval()" without the "$" symbol and it also works very nicely. Thanks for your assistance, I really appreciate all you guys assistance. Gerry 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