GileraGFR Posted September 29, 2009 Posted September 29, 2009 Hi Peeps, I've used AutoIT for quite a while, mainly just for automating the installation of applications that have many steps. I'm trying to write a very simple GUI that has checkboxes displayed which when ticked and a button is then pressed the relevant apps which the checkboxes relate to would install - simple i thought. All the apps i need to install are part of a single AutoIT script as funtions() with just an if statement for each app checking if it's already installed, so i just need to call the each of the apps func() to install it. I've attached what i have so far (please don't laugh), i think you should be able to work out what i'm trying to do. It kind of works at the moment but it will only install one application because if more than one checkbox is ticked it ignores the others because of the way i have the if statements - which leads me back to thinking i'm going about this in completly the wrong way. I don't want anyone to e-write anything but if someone could mention what would be a better way and point me in the right direction that would be great. #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 185, 185, 192, 124) $Button1 = GUICtrlCreateButton("Install", 8, 160, 107, 25, $WS_GROUP) $Checkbox1 = GUICtrlCreateCheckbox("Install App#1", 8, 20, 97, 17) $Checkbox2 = GUICtrlCreateCheckBox("Install App#2", 8, 40, 97, 17) $Checkbox3 = GUICtrlCreateCheckBox("Install App#3", 8, 60, 97, 17) $Checkbox4 = GUICtrlCreateCheckBox("Install App#4", 8, 80, 97, 17) $Checkbox5 = GUICtrlCreateCheckBox("Install App#5", 8, 100, 97, 17) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ;You clicked the X Exit Case $Button1 If GUICtrlRead($Checkbox1) $GUI_CHECKED Then MsgBox(4096, "Install", "App1") ;replace with app1 installation func() ElseIf GUICtrlRead($Checkbox2) = $GUI_CHECKED Then MsgBox(4096, "Install", "App2") ElseIf GUICtrlRead($Checkbox3) = $GUI_CHECKED Then MsgBox(4096, "Install", "App3") ElseIf GUICtrlRead($Checkbox4) = $GUI_CHECKED Then MsgBox(4096, "Install", "App4") ElseIf GUICtrlRead($Checkbox5) = $GUI_CHECKED Then MsgBox(4096, "Install", "App5") EndIf EndSwitch WEnd Thanks
Moderators Melba23 Posted September 29, 2009 Moderators Posted September 29, 2009 (edited) GileraGFR,You are very nearly there! Just check each checkbox in turn rather than using the multiple ElseIf construct. As you have found, that only allows for a single case to be installed. Pseudo-code:If check1 checked Then install A If check2 checked Then install B If check3 checked Then install C...etcM23P.S. Welcome to the AutoIt forums, by the way! Edited September 29, 2009 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
smashly Posted September 29, 2009 Posted September 29, 2009 (edited) Hi,#include <GUIConstantsEx.au3> Global $Form1, $Button1, $aCheckbox[5], $nMsg $Form1 = GUICreate("Form1", 185, 185, 192, 124) $Button1 = GUICtrlCreateButton("Install", 8, 160, 107, 25) For $i = 0 To UBound($aCheckbox) - 1 $aCheckbox[$i] = GUICtrlCreateCheckbox("Install App#" & $i + 1, 8, ($i * 20) + 20, 97, 17) Next GUISetState(@SW_SHOW, $Form1) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ;You clicked the X Exit Case $Button1 For $i = 0 To UBound($aCheckbox) - 1 If BitAND(GUICtrlRead($aCheckbox[$i]), $GUI_CHECKED) Then MsgBox(4096, "Install", "App" & $i + 1) Next EndSwitch WEnd Cheers Edited September 29, 2009 by smashly
GileraGFR Posted September 30, 2009 Author Posted September 30, 2009 Spot on guys, thanks for the quick responses, I'll check each one out and see which will be easier to amend in the future if i add more to it. Thanks again.
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