Jump to content

Recommended Posts

Posted

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
Posted (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...etc

M23

P.S. Welcome to the AutoIt forums, by the way!

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted (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 by smashly
Posted

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.

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...