Jump to content

Checkbox Combinations


Recommended Posts

Hello all,

Im trying to figure out how to make my script detect checkbox combinations to run different exe's. For example if I had four checkboxes 1, 2, 3, 4 and I wanted calc.exe to run when checkboxes 1 & 2 where checked or if i wanted notepad.exe to run when 2 & 4 were checked. I have my checkboxes setup but I cannot figure out how to make two true statements. Any input would be appreciated.

Link to comment
Share on other sites

I made this quickly, but it should get you started in the right direction. Just add your own cases to the code (at line 26)

;AutoIt Version: 3.2.1.14 (beta)

#region --- GuiBuilder code Start ---
; Script generated by AutoBuilder 0.6 Prototype

#include <GuiConstants.au3>

GuiCreate("MyGUI", 114, 207,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$Checkbox_1 = GuiCtrlCreateCheckbox("Checkbox1", 10, 10, 100, 30)
$Checkbox_2 = GuiCtrlCreateCheckbox("Checkbox2", 10, 40, 100, 40)
$Checkbox_3 = GuiCtrlCreateCheckbox("Checkbox3", 10, 80, 100, 40)
$Checkbox_4 = GuiCtrlCreateCheckbox("Checkbox4", 10, 120, 100, 40)
$Button_5 = GuiCtrlCreateButton("Button5", 10, 170, 80, 30)

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Button_5
        Select
            Case GUICtrlRead($Checkbox_1) = $GUI_CHECKED And GUICtrlRead($Checkbox_2) = $GUI_UNCHECKED And GUICtrlRead($Checkbox_3) = $GUI_UNCHECKED And GUICtrlRead($Checkbox_4) = $GUI_UNCHECKED
                MsgBox(0, "Checkbox", "checkbox 1 checked")
                
        EndSelect
    Case Else
        ;;;
    EndSelect
WEnd
Exit
#endregion --- GuiBuilder generated code End ---

btw it helps if you post some sample code when asking for help :shocked:

Edited by Kourath
Link to comment
Share on other sites

Something like this ?

#include <GuiConstants.au3>

Opt("GUIOnEventMode", 1)
Opt("RunErrorsFatal", 0)

Global $sPid[2]

$Main = GuiCreate("MyGUI", 150, 169,-1, -1)
WinSetOnTop($Main,"",1)
$Checkbox_1 = GuiCtrlCreateCheckbox("Checkbox1", 20, 30, 110, 20)
GUICtrlSetOnEvent(-1, '_checkbox')
$Checkbox_2 = GuiCtrlCreateCheckbox("Checkbox2", 20, 60, 100, 20)
GUICtrlSetOnEvent(-1, '_checkbox')
$Checkbox_3 = GuiCtrlCreateCheckbox("Checkbox3", 20, 90, 100, 20)
GUICtrlSetOnEvent(-1, '_checkbox')
$Checkbox_4 = GuiCtrlCreateCheckbox("Checkbox4", 20, 120, 110, 20)
GUICtrlSetOnEvent(-1, '_checkbox')
GUISetOnEvent($GUI_EVENT_CLOSE, '_checkbox')
GuiSetState()

While 1
    Sleep(10)
WEnd

Func _checkbox()
    Select
        Case @GUI_CTRLID = $Checkbox_1
            If GUICtrlRead($Checkbox_1) = $GUI_CHECKED And GUICtrlRead($Checkbox_2) = $GUI_CHECKED Then
                $pid = Run(@SystemDir & '\notepad.exe')
                If @error <> 1 Then
                    $sPid[0] = $pid
                EndIf   
            ElseIf GUICtrlRead($Checkbox_1) = $GUI_UNCHECKED And ProcessExists($sPid[0]) Then
                ProcessClose($sPid[0])
                $sPid[0] = ''
            EndIf
        Case @GUI_CTRLID = $Checkbox_2
            If GUICtrlRead($Checkbox_1) = $GUI_CHECKED And GUICtrlRead($Checkbox_2) = $GUI_CHECKED Then
                $pid = Run(@SystemDir & '\notepad.exe')
                If @error <> 1 Then
                    $sPid[0] = $pid
                EndIf   
            ElseIf GUICtrlRead($Checkbox_2) = $GUI_UNCHECKED And ProcessExists($sPid[0]) Then
                ProcessClose($sPid[0])
                $sPid[0] = ''               
            EndIf           
        Case @GUI_CTRLID = $Checkbox_3
            If GUICtrlRead($Checkbox_3) = $GUI_CHECKED And GUICtrlRead($Checkbox_4) = $GUI_CHECKED Then
                $pid = Run(@SystemDir & '\calc.exe')
                If @error <> 1 Then
                    $sPid[1] = $pid
                EndIf   
            ElseIf GUICtrlRead($Checkbox_3) = $GUI_UNCHECKED And ProcessExists($sPid[1]) Then
                ProcessClose($sPid[1])
                $sPid[1] = ''           
            EndIf   
        Case @GUI_CTRLID = $Checkbox_4
            If GUICtrlRead($Checkbox_3) = $GUI_CHECKED And GUICtrlRead($Checkbox_4) = $GUI_CHECKED Then
                $pid = Run(@SystemDir & '\calc.exe')
                If @error <> 1 Then
                    $sPid[1] = $pid
                EndIf   
            ElseIf GUICtrlRead($Checkbox_4) = $GUI_UNCHECKED And ProcessExists($sPid[1]) Then
                ProcessClose($sPid[1])
                $sPid[1] = ''           
            EndIf   
        Case @GUI_CTRLID = $GUI_EVENT_CLOSE
            Exit
    EndSelect
EndFunc

Since you've posted no code I can only guess....

Cheers

Doh I was to slow .. once again ...

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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