azler1 Posted April 20, 2009 Share Posted April 20, 2009 I have made a script for auto IT nothing special, you run it, it checks if a program is installed, if not it installs it if it is it does not. pretty simple right? So i wanted to expand on this by giving it a gui menu. So what i had in mind is: 6+ check boxes and a 'Go' button. You select what you want then click go, and it installs it. expandcollapse popup#include <GUIConstantsEx.au3> Opt('MustDeclareVars', 1) _Main() Func _Main() Local $msg, $okbutton, $cancelbutton #forceref $separator1 GUICreate("GUI menu", 300, 400) $okbutton = GUICtrlCreateButton("OK", 50, 200, 70, 20) $cancelbutton = GUICtrlCreateButton("Cancel", 180, 200, 70, 20) GUISetState() GuiCtrlCreateCheckbox("1", 10, 20, 80, 20) guiCtrlCreateCheckbox("2", 10, 40, 80, 20) GuiCtrlCreateCheckbox("3", 10, 60, 80, 20) GuiCtrlCreateCheckbox("4", 10, 80, 80, 20) GuiCtrlCreateCheckbox("5", 10, 100, 80, 20) GuiCtrlCreateCheckbox("6", 10, 120, 80, 20) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton ExitLoop Case $msg = $okbutton MsgBox(0, "Click", $GUI_CHECKED) EndSelect WEnd GUIDelete() Exit EndFunc ;==>_Main As you can tell i got some of my code from the examples. Could some one please show me how to: set a value for each check box. When you click 'Go', tell you which boxes you selected? and then how to run all the values of the check boxes in order 'Runwait' az Link to comment Share on other sites More sharing options...
GEOSoft Posted April 20, 2009 Share Posted April 20, 2009 Use GUICtrlSetState() to set them.That code is generaly a mess.1- create the checkboxes before the GUISetState()2- create the checkboxes as named variables.$Cbx1 = GuiCtrlCreateCheckbox("1", 10, 20, 80, 20) $Cbx2 = guiCtrlCreateCheckbox("2", 10, 40, 80, 20) $Cbx3 = GuiCtrlCreateCheckbox("3", 10, 60, 80, 20) $Cbx4 = GuiCtrlCreateCheckbox("4", 10, 80, 80, 20) $Cbx5 = GuiCtrlCreateCheckbox("5", 10, 100, 80, 20) $Cbx6 = GuiCtrlCreateCheckbox("6", 10, 120, 80, 20)Then look in the help file for GUICtrlRead() for examples of reading the checked values. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
stampy Posted April 20, 2009 Share Posted April 20, 2009 To interact with checkboxes they need to defined as a variable. I've used an array below as it's easy to loop through them then. However you could use a standard variable. To set them use GUICTRLSETSTATE. To read if they are checked use GUICTRLREAD. Both are explained in the help file along with using BitAnd to read. expandcollapse popup#include <GUIConstantsEx.au3> Opt('MustDeclareVars', 1) _Main() Func _Main() Local $msg, $okbutton, $cancelbutton GUICreate("GUI menu", 300, 400) $okbutton = GUICtrlCreateButton("OK", 50, 200, 70, 20) $cancelbutton = GUICtrlCreateButton("Cancel", 180, 200, 70, 20) Dim $CbxArray[6] $CbxArray[0] = GuiCtrlCreateCheckbox("1", 10, 20, 80, 20) GUICtrlSetState(-1,$GUI_CHECKED) ;when first shown default it checked $CbxArray[1] = guiCtrlCreateCheckbox("2", 10, 40, 80, 20) $CbxArray[2] = GuiCtrlCreateCheckbox("3", 10, 60, 80, 20) GUICtrlSetState(-1,$GUI_CHECKED) ;when first shown default it checked $CbxArray[3] = GuiCtrlCreateCheckbox("4", 10, 80, 80, 20) $CbxArray[4] = GuiCtrlCreateCheckbox("5", 10, 100, 80, 20) $CbxArray[5] = GuiCtrlCreateCheckbox("6", 10, 120, 80, 20) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton ExitLoop Case $msg = $okbutton For $i = 0 to UBound($CbxArray)-1 If BitAnd(GUICtrlRead($CbxArray[$i]),$GUI_CHECKED)Then MsgBox(0, "Click", 'Checkbox ' & $i+1 & ' is checked') EndIf Next EndSelect WEnd GUIDelete() Exit EndFunc ;==>_Main Link to comment Share on other sites More sharing options...
azler1 Posted April 21, 2009 Author Share Posted April 21, 2009 Case $msg = $okbutton For $i = 0 to UBound($CbxArray)-1 If BitAnd(GUICtrlRead($CbxArray[$i]),$GUI_CHECKED)Then MsgBox(0, "Click", 'Checkbox ' & $i+1 & ' is checked') EndIf Next yeh this is what im after! =] so if i replace: Case $msg = $okbutton For $i = 0 to UBound($CbxArray)-1 If BitAnd(GUICtrlRead($CbxArray[$i]),$GUI_CHECKED)Then RunWait( $i+1) EndIf Next it would runwait the value.. but how do i set a value? as the name is '1' so how to i get it to say for example in the gui next to the checkbox 'Ccleaner' and then when its run in the code its run 'ccleaner.exe /AUTO'? az Link to comment Share on other sites More sharing options...
Zedna Posted April 21, 2009 Share Posted April 21, 2009 (edited) Case $msg = $okbutton For $i = 0 to UBound($CbxArray)-1 If BitAnd(GUICtrlRead($CbxArray[$i]),$GUI_CHECKED)Then RunWait( GUICtrlRead($CbxArray[$i], 1)) EndIf Next Edited April 21, 2009 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
azler1 Posted April 21, 2009 Author Share Posted April 21, 2009 But how do i set a different value of it? if you understand me. i guess im thinking of it a little like php.. not sure if it can do what i want =[ Link to comment Share on other sites More sharing options...
azler1 Posted April 23, 2009 Author Share Posted April 23, 2009 expandcollapse popup#include <GUIConstantsEx.au3> Opt('MustDeclareVars', 1) _Main() Func _Main() Local $msg, $okbutton, $cancelbutton GUICreate("GUI menu", 300, 400) $okbutton = GUICtrlCreateButton("OK", 50, 200, 70, 20) $cancelbutton = GUICtrlCreateButton("Cancel", 180, 200, 70, 20) Dim $CbxArray[6] $CbxArray[0] = GuiCtrlCreateCheckbox("CCleaner", 10, 20, 80, 20) $CbxArray[1] = guiCtrlCreateCheckbox("Program 2", 10, 40, 80, 20) $CbxArray[2] = GuiCtrlCreateCheckbox("AVG", 10, 60, 80, 20) $CbxArray[3] = GuiCtrlCreateCheckbox("etc", 10, 80, 80, 20) $CbxArray[4] = GuiCtrlCreateCheckbox("5", 10, 100, 80, 20) $CbxArray[5] = GuiCtrlCreateCheckbox("6", 10, 120, 80, 20) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton ExitLoop Case $msg = $okbutton For $i = 0 to UBound($CbxArray)-1 If BitAnd(GUICtrlRead($CbxArray[$i]),$GUI_CHECKED)Then RunWait( GUICtrlRead($CbxArray[$i], 1)) EndIf Next EndSelect WEnd GUIDelete() Exit EndFunc ;==>_Main So this is what i have so far. but when i click the ok button ir just does the runwait what ever is checked so if i check ccleaner it just runwaits that. How do i get it to 'runwait ccleaner.exe /AUTO' when the ccleaner is checked? Link to comment Share on other sites More sharing options...
Zedna Posted April 23, 2009 Share Posted April 23, 2009 expandcollapse popup#include <GUIConstantsEx.au3> Opt('MustDeclareVars', 1) Local $msg, $okbutton, $cancelbutton GUICreate("GUI menu", 300, 400) $okbutton = GUICtrlCreateButton("OK", 50, 200, 70, 20) $cancelbutton = GUICtrlCreateButton("Cancel", 180, 200, 70, 20) Dim $CbxArray[6] $CbxArray[0] = GUICtrlCreateCheckbox("CCleaner", 10, 20, 80, 20) $CbxArray[1] = GUICtrlCreateCheckbox("Program 2", 10, 40, 80, 20) $CbxArray[2] = GUICtrlCreateCheckbox("AVG", 10, 60, 80, 20) $CbxArray[3] = GUICtrlCreateCheckbox("etc", 10, 80, 80, 20) $CbxArray[4] = GUICtrlCreateCheckbox("5", 10, 100, 80, 20) $CbxArray[5] = GUICtrlCreateCheckbox("6", 10, 120, 80, 20) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton ExitLoop Case $msg = $okbutton For $i = 0 To UBound($CbxArray) - 1 If BitAND(GUICtrlRead($CbxArray[$i]), $GUI_CHECKED) Then RunWait(GetProgramCommand(GUICtrlRead($CbxArray[$i], 1))) EndIf Next EndSelect WEnd Func GetProgramCommand($program) Local $command Switch $program Case "CCleaner" $command = "ccleaner.exe /AUTO" Case "Program 2" $command = "Program2.exe /c" Case "..." $command = "..." EndSwitch Return $command EndFunc Resources UDF ResourcesEx UDF AutoIt Forum Search 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