Jump to content

Checkbox, arrays and functions...


Recommended Posts

Hi, I am trying to learn autoit here.

I am creating a gui with some checkboxes. Each checkbox is related to a function. I would like execute the functions one by one.

So in this example when  both are checked, both msgboxes should appear.

Below is my latest test and trial, but it does not work I tried to create an array, but I could not find a simple example.

Most of the time the function is called immediately when checked.

Hope someone can explain / provide a simple example how to do this.

 

Thank you

 

#include <GUIConstantsEx.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 286, 317, 393, 125)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 24, 24, 225, 17)
$Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 24, 54, 225, 17)
$runButton = GUICtrlCreateButton("Run", 24, 156, 81, 41, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $runButton
           if  BitAnd(GuiCtrlRead($Checkbox1),$GUI_CHECKED) then
         msg1()
        elseif BitAnd(GuiCtrlRead($Checkbox2),$GUI_CHECKED) then
         msg2()
           endif
           sleep(10)
    EndSwitch
WEnd

func  msg1()
        Msgbox(0,"Winner","The checkbox is ticked")
        EndFunc

func msg2()
        Msgbox(0,"Winner","The checkbox 2  is also ticked")
        endfunc

 

 

 

Link to comment
Share on other sites

Try it this way. You can't check 2 conditions in an If statement like that, as soon as it finds one match to your comparisons, it ignores the rest.

#include <GUIConstantsEx.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 286, 317, 393, 125)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 24, 24, 225, 17)
$Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 24, 54, 225, 17)
$runButton = GUICtrlCreateButton("Run", 24, 156, 81, 41, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
     $nMsg = GUIGetMsg()
     Switch $nMsg
          Case $GUI_EVENT_CLOSE
               Exit
          Case $runButton
               If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
                    msg1()
               EndIf
               If GUICtrlRead($Checkbox2) = $GUI_CHECKED Then
                    msg2()
               EndIf
               Sleep(10)
     EndSwitch
WEnd

Func msg1()
     MsgBox(0, "Winner", "The checkbox is ticked")
EndFunc   ;==>msg1

Func msg2()
     MsgBox(0, "Winner", "The checkbox 2  is also ticked")
EndFunc   ;==>msg2

I also fixed your GUICTRLRead functions for the checkboxes, there's no need to use BitAnd with it.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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