Sign in to follow this  
Followers 0
jerem488

How to call function of checkbox of array ?

8 posts in this topic

Hi,

I have a problem to call the function with it's name.

I created multiple checkbox with the array, then when I want to read the state of checkboxes, I can't recover it.

In this program, I want to call function with it's name. Before I must check the state of the checkbox, and I don't know how to do. :(

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
#include <ProgressConstants.au3>
#include <Array.au3>
$Fenetre_principale = GUICreate("Outils de sécurité", 300, 280)
$Tailles_fenetre = WinGetPos("Outils de sécurité")
$Label_enregistrement = GUICtrlCreateLabel("Dossier d'enregistrement : ", 10, 12, 150)
GUICtrlSetFont($Label_enregistrement, 8.5, 600, 4)
GUICtrlSetColor($Label_enregistrement, 0x007399)
$Boutton_selection_dossier = GUICtrlCreateButton("Sélectionner", 165, 8, 87, 25)
$Label_selection_dossier = GUICtrlCreateInput("", 10, 40, 280, 21)
$Executer = GUICtrlCreateButton("Executer", $Tailles_fenetre[2]/3 - 75, $Tailles_fenetre[3] - 69, 100)
$Ouvrir_dossier = GUICtrlCreateButton("Ouvrir le dossier", $Tailles_fenetre[2] - $Tailles_fenetre[2]/3 - 35, $Tailles_fenetre[3] - 69, 100)
GUICtrlSetState($Executer, $GUI_DISABLE)
GUICtrlSetState($Ouvrir_dossier, $GUI_DISABLE)
Global $Array[6]
$Array[0] = "Stinger"
$Array[1] = "Spybot"
$Array[2] = "Dr.Web CureIt!"
$Array[3] = "Malwarebytes"
$Array[4] = "AdwCleaner"
$Array[5] = "Gmer"
$Top = 70
; 1st) ------------
For $i = 0 To UBound($Array, 1) - 1
$Array[$i] = GUICtrlCreateCheckbox($Array[$i], 10, $Top, 120)
GUICtrlSetFont($Array, 8.5, 400, 4)
GUICtrlCreateProgress(130, $Top, 128)
GUICtrlCreateLabel("", 263, $Top, 37, 21, $SS_CENTERIMAGE)
$Top += 25
Next
; 2nd) ------------
For $Programmes In $Array
ConsoleWrite("AB : " & $Programmes & @CRLF)
$Checkbox = GUICtrlCreateCheckbox($Programmes, 10, $Top, 120)
GUICtrlSetFont($Checkbox, 8.5, 400, 4)
GUICtrlCreateProgress(130, $Top, 128)
GUICtrlCreateLabel("", 263, $Top, 37, 21, $SS_CENTERIMAGE)
$Top += 25
ConsoleWrite($Checkbox & @CRLF)
Next
; ------------
GUISetState()
Do
$Action = GUIGetMsg()
Select
  Case $Action = $Boutton_selection_dossier
   $Selection_dossier = FileSelectFolder("Veuillez sélectionner l'emplacement des téléchargements :", @HomeDrive & "\")
   If @error <> 1 Then
    If StringRight($Selection_dossier, 1) <> "\" Then
     $Emplacement_des_telechargements = $Selection_dossier & "\__Programmes de sécurité__"
    Else
     $Emplacement_des_telechargements = $Selection_dossier & "__Programmes de sécurité__"
    EndIf
    GUICtrlSetData($Label_selection_dossier, $Emplacement_des_telechargements)
    GUICtrlSetState($Executer, $GUI_ENABLE)
   EndIf
  Case $Action = $Executer
;~    DirCreate($Emplacement_des_telechargements)
;~    GUICtrlSetState($Ouvrir_dossier, $GUI_ENABLE)
  Case $Action = $Ouvrir_dossier
   ShellExecute($Emplacement_des_telechargements)
EndSelect
Until $Action = $GUI_EVENT_CLOSE
Func Stinger()
EndFunc

Thanks in advance


Qui ose gagneWho Dares Win[left]CyberExploit[/left]

Share this post


Link to post
Share on other sites

jerem488,

This may help

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>

#AutoIt3Wrapper_Add_Constants=n

local $ckb_cntrls[16], $msg

local $gui010 = guicreate('Checkbox Controls Using an Array for the Control ID')

for $1 = 1 to 15
    $ckb_cntrls[$1] = GUICtrlCreateCheckbox('CheckBox #' & stringformat('%02i',$1),95, $1 * 25,140,15)
Next

guisetstate()

while 1

    $msg = guigetmsg()

    switch $msg
        case $gui_event_close
            Exit
        case $ckb_cntrls[1] to $ckb_cntrls[ubound($ckb_cntrls) - 1]
            local $h = _winapi_getfocus()
            ConsoleWrite($h & @LF)
            ConsoleWrite('Last action on ' & wingettitle($h) & @LF)
            for $1 = 1 to ubound($ckb_cntrls) - 1
                if guictrlread($ckb_cntrls[$1]) = $gui_checked then
                    ConsoleWrite('Checkbox #' & stringformat('%02i',$1) & ' checked' & @LF)
                else
                    ConsoleWrite('Checkbox #' & stringformat('%02i',$1) & ' unchecked' & @LF)
                endif
            next
    EndSwitch

wend

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

jerem488,

This may help

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>

#AutoIt3Wrapper_Add_Constants=n

local $ckb_cntrls[16], $msg

local $gui010 = guicreate('Checkbox Controls Using an Array for the Control ID')

for $1 = 1 to 15
    $ckb_cntrls[$1] = GUICtrlCreateCheckbox('CheckBox #' & stringformat('%02i',$1),95, $1 * 25,140,15)
Next

guisetstate()

while 1

    $msg = guigetmsg()

    switch $msg
        case $gui_event_close
            Exit
        case $ckb_cntrls[1] to $ckb_cntrls[ubound($ckb_cntrls) - 1]
            local $h = _winapi_getfocus()
            ConsoleWrite($h & @LF)
            ConsoleWrite('Last action on ' & wingettitle($h) & @LF)
            for $1 = 1 to ubound($ckb_cntrls) - 1
                if guictrlread($ckb_cntrls[$1]) = $gui_checked then
                    ConsoleWrite('Checkbox #' & stringformat('%02i',$1) & ' checked' & @LF)
                else
                    ConsoleWrite('Checkbox #' & stringformat('%02i',$1) & ' unchecked' & @LF)
                endif
            next
    EndSwitch

wend

kylomas

With your example, I can find the ID of the value, but not his value :(

Qui ose gagneWho Dares Win[left]CyberExploit[/left]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

jerem488,

My example was to demonstrate an array of checkboxes. I'm not sure what you mean by this

With your example, I can find the ID of the value, but not his value

kylomas

edit: After taking a closer look at your code it looks like you are overwriting your array with control ID's.

Are you trying to make a table with values that correspond to a checkbox?

It looks like you are also overlaying your controls.

I changed the length of your gui to 580 and it's displaying correctly.

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

jerem488,

Is this what you are trying to do? (see comments in code)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
#include <ProgressConstants.au3>
#include <Array.au3>
$Fenetre_principale = GUICreate("Outils de sécurité", 300, 580)
$Tailles_fenetre = WinGetPos("Outils de sécurité")
$Label_enregistrement = GUICtrlCreateLabel("Dossier d'enregistrement : ", 10, 12, 150)
GUICtrlSetFont($Label_enregistrement, 8.5, 600, 4)
GUICtrlSetColor($Label_enregistrement, 0x007399)
$Boutton_selection_dossier = GUICtrlCreateButton("Sélectionner", 165, 8, 87, 25)
$Label_selection_dossier = GUICtrlCreateInput("", 10, 40, 280, 21)
$Executer = GUICtrlCreateButton("Executer", $Tailles_fenetre[2] / 3 - 75, $Tailles_fenetre[3] - 69, 100)
$Ouvrir_dossier = GUICtrlCreateButton("Ouvrir le dossier", $Tailles_fenetre[2] - $Tailles_fenetre[2] / 3 - 35, $Tailles_fenetre[3] - 69, 100)
GUICtrlSetState($Executer, $GUI_DISABLE)
GUICtrlSetState($Ouvrir_dossier, $GUI_DISABLE)

; changed the following array to 2D
;
;   offset [0][0] = control id
;   offset [0][1] = value

Global $Array[6][2]
$Array[0][1] = "Stinger"
$Array[1][1] = "Spybot"
$Array[2][1] = "Dr.Web CureIt!"
$Array[3][1] = "Malwarebytes"
$Array[4][1] = "AdwCleaner"
$Array[5][1] = "Gmer"
$Top = 70
; 1st) ------------
For $i = 0 To UBound($Array, 1) - 1
    $Array[$i][0] = GUICtrlCreateCheckbox($Array[$i][1], 10, $Top, 120)
    GUICtrlSetFont($Array, 8.5, 400, 4)
    GUICtrlCreateProgress(130, $Top, 128)
    GUICtrlCreateLabel("", 263, $Top, 37, 21, $SS_CENTERIMAGE)
    $Top += 25

    ; changed this to display values in a 2D array

    ConsoleWrite('controlid = ' & $array[$i][0] & '  programm = ' & $array[$i][1] & @LF)
Next


GUISetState()
Do
    $Action = GUIGetMsg()
    Select
        Case $Action = $Boutton_selection_dossier
            $Selection_dossier = FileSelectFolder("Veuillez sélectionner l'emplacement des téléchargements :", @HomeDrive & "\")
            If @error <> 1 Then
                If StringRight($Selection_dossier, 1) <> "\" Then
                    $Emplacement_des_telechargements = $Selection_dossier & "\__Programmes de sécurité__"
                Else
                    $Emplacement_des_telechargements = $Selection_dossier & "__Programmes de sécurité__"
                EndIf
                GUICtrlSetData($Label_selection_dossier, $Emplacement_des_telechargements)
                GUICtrlSetState($Executer, $GUI_ENABLE)
            EndIf
        Case $Action = $Executer
;~    DirCreate($Emplacement_des_telechargements)
;~    GUICtrlSetState($Ouvrir_dossier, $GUI_ENABLE)
        Case $Action = $Ouvrir_dossier
            ShellExecute($Emplacement_des_telechargements)
    EndSelect
Until $Action = $GUI_EVENT_CLOSE
Func Stinger()
EndFunc   ;==>Stinger

If not, please clarify your task.

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

jerem488,

Final change till you post again.

I changed your msg loop to "switch' from "select" so that it works with a range of checkbox controls.

The code writes a console mesage for whatever programm is checked. Beyond this, I have no idea what you are doing, assuming that this is even close.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
#include <ProgressConstants.au3>
#include <Array.au3>
$Fenetre_principale = GUICreate("Outils de sécurité", 300, 580)
$Tailles_fenetre = WinGetPos("Outils de sécurité")
$Label_enregistrement = GUICtrlCreateLabel("Dossier d'enregistrement : ", 10, 12, 150)
GUICtrlSetFont($Label_enregistrement, 8.5, 600, 4)
GUICtrlSetColor($Label_enregistrement, 0x007399)
$Boutton_selection_dossier = GUICtrlCreateButton("Sélectionner", 165, 8, 87, 25)
$Label_selection_dossier = GUICtrlCreateInput("", 10, 40, 280, 21)
$Executer = GUICtrlCreateButton("Executer", $Tailles_fenetre[2] / 3 - 75, $Tailles_fenetre[3] - 69, 100)
$Ouvrir_dossier = GUICtrlCreateButton("Ouvrir le dossier", $Tailles_fenetre[2] - $Tailles_fenetre[2] / 3 - 35, $Tailles_fenetre[3] - 69, 100)
GUICtrlSetState($Executer, $GUI_DISABLE)
GUICtrlSetState($Ouvrir_dossier, $GUI_DISABLE)

; changed the following array to 2D
;
;   offset [0][0] = control id
;   offset [0][1] = value

Global $Array[6][2]
$Array[0][1] = "Stinger"
$Array[1][1] = "Spybot"
$Array[2][1] = "Dr.Web CureIt!"
$Array[3][1] = "Malwarebytes"
$Array[4][1] = "AdwCleaner"
$Array[5][1] = "Gmer"
$Top = 70
; 1st) ------------
For $i = 0 To UBound($Array, 1) - 1
    $Array[$i][0] = GUICtrlCreateCheckbox($Array[$i][1], 10, $Top, 120)
    GUICtrlSetFont($Array, 8.5, 400, 4)
    GUICtrlCreateProgress(130, $Top, 128)
    GUICtrlCreateLabel("", 263, $Top, 37, 21, $SS_CENTERIMAGE)
    $Top += 25

    ; changed this to display values in a 2D array

    ConsoleWrite('controlid = ' & $array[$i][0] & '  programm = ' & $array[$i][1] & @LF)
Next


GUISetState()
Do

    ; changed your message loop to use switch

    $Action = GUIGetMsg()
    switch $Action
        Case $Boutton_selection_dossier
            $Selection_dossier = FileSelectFolder("Veuillez sélectionner l'emplacement des téléchargements :", @HomeDrive & "\")
            If @error <> 1 Then
                If StringRight($Selection_dossier, 1) <> "\" Then
                    $Emplacement_des_telechargements = $Selection_dossier & "\__Programmes de sécurité__"
                Else
                    $Emplacement_des_telechargements = $Selection_dossier & "__Programmes de sécurité__"
                EndIf
                GUICtrlSetData($Label_selection_dossier, $Emplacement_des_telechargements)
                GUICtrlSetState($Executer, $GUI_ENABLE)
            EndIf
        Case $Executer

;~    DirCreate($Emplacement_des_telechargements)
;~    GUICtrlSetState($Ouvrir_dossier, $GUI_ENABLE)
        Case $Ouvrir_dossier
            ShellExecute($Emplacement_des_telechargements)

        ; this is how you might check your checkboxes

        case $array[0][0] to $array[ubound($array,1)-1][0]
            for $1 = 0 to ubound($array,1) - 1
                if guictrlread($array[$1][0]) = $gui_checked then ConsoleWrite('program = '  & $array[$1][1] & ' checked' & @LF)
            next

    EndSwitch
Until $Action = $GUI_EVENT_CLOSE
Func Stinger()
EndFunc   ;==>Stinger

kylomas

1 person likes this

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

jerem488,

Final change till you post again.

I changed your msg loop to "switch' from "select" so that it works with a range of checkbox controls.

The code writes a console mesage for whatever programm is checked. Beyond this, I have no idea what you are doing, assuming that this is even close.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
#include <ProgressConstants.au3>
#include <Array.au3>
$Fenetre_principale = GUICreate("Outils de sécurité", 300, 580)
$Tailles_fenetre = WinGetPos("Outils de sécurité")
$Label_enregistrement = GUICtrlCreateLabel("Dossier d'enregistrement : ", 10, 12, 150)
GUICtrlSetFont($Label_enregistrement, 8.5, 600, 4)
GUICtrlSetColor($Label_enregistrement, 0x007399)
$Boutton_selection_dossier = GUICtrlCreateButton("Sélectionner", 165, 8, 87, 25)
$Label_selection_dossier = GUICtrlCreateInput("", 10, 40, 280, 21)
$Executer = GUICtrlCreateButton("Executer", $Tailles_fenetre[2] / 3 - 75, $Tailles_fenetre[3] - 69, 100)
$Ouvrir_dossier = GUICtrlCreateButton("Ouvrir le dossier", $Tailles_fenetre[2] - $Tailles_fenetre[2] / 3 - 35, $Tailles_fenetre[3] - 69, 100)
GUICtrlSetState($Executer, $GUI_DISABLE)
GUICtrlSetState($Ouvrir_dossier, $GUI_DISABLE)

; changed the following array to 2D
;
; offset [0][0] = control id
; offset [0][1] = value

Global $Array[6][2]
$Array[0][1] = "Stinger"
$Array[1][1] = "Spybot"
$Array[2][1] = "Dr.Web CureIt!"
$Array[3][1] = "Malwarebytes"
$Array[4][1] = "AdwCleaner"
$Array[5][1] = "Gmer"
$Top = 70
; 1st) ------------
For $i = 0 To UBound($Array, 1) - 1
    $Array[$i][0] = GUICtrlCreateCheckbox($Array[$i][1], 10, $Top, 120)
    GUICtrlSetFont($Array, 8.5, 400, 4)
    GUICtrlCreateProgress(130, $Top, 128)
    GUICtrlCreateLabel("", 263, $Top, 37, 21, $SS_CENTERIMAGE)
    $Top += 25

    ; changed this to display values in a 2D array

    ConsoleWrite('controlid = ' & $array[$i][0] & ' programm = ' & $array[$i][1] & @LF)
Next


GUISetState()
Do

    ; changed your message loop to use switch

    $Action = GUIGetMsg()
    switch $Action
        Case $Boutton_selection_dossier
            $Selection_dossier = FileSelectFolder("Veuillez sélectionner l'emplacement des téléchargements :", @HomeDrive & "\")
            If @error <> 1 Then
                If StringRight($Selection_dossier, 1) <> "\" Then
                    $Emplacement_des_telechargements = $Selection_dossier & "\__Programmes de sécurité__"
                Else
                    $Emplacement_des_telechargements = $Selection_dossier & "__Programmes de sécurité__"
                EndIf
                GUICtrlSetData($Label_selection_dossier, $Emplacement_des_telechargements)
                GUICtrlSetState($Executer, $GUI_ENABLE)
            EndIf
        Case $Executer

;~ DirCreate($Emplacement_des_telechargements)
;~ GUICtrlSetState($Ouvrir_dossier, $GUI_ENABLE)
        Case $Ouvrir_dossier
            ShellExecute($Emplacement_des_telechargements)

        ; this is how you might check your checkboxes

        case $array[0][0] to $array[ubound($array,1)-1][0]
            for $1 = 0 to ubound($array,1) - 1
                if guictrlread($array[$1][0]) = $gui_checked then ConsoleWrite('program = ' & $array[$1][1] & ' checked' & @LF)
            next

    EndSwitch
Until $Action = $GUI_EVENT_CLOSE
Func Stinger()
EndFunc ;==>Stinger

kylomas

Kylomas, you are simply a genious ! I didn't use an array 2D... but we haven't choice to do this.

Qui ose gagneWho Dares Win[left]CyberExploit[/left]

Share this post


Link to post
Share on other sites

Kylomas, you are simply a genious !

Hardly, these are all common techniques as you will see from reading the forum.

Good Luck,

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
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
Sign in to follow this  
Followers 0