Search code examples
for-loopautoit

Reading from check boxes doesn't work


I want to iterate through check boxes to get the caption text from each one. I have this code but it is not working. Could someone tell me whats wrong?

Is that because later in the For loop I am using $i to iterate through other things? But it doesn't even run the Send() command. Does AutoIt increment the $i variable automatically?

For $i = 1 to 64
    If GUICtrlRead("$Checkbox" & $i,0) = $GUI_CHECKED Then
        Local $checkboxtext = GUICtrlRead($Checkbox[$i], 1)
        Local $checkboxtextsplit = StringSplit( $checkboxtext, "/")
        $instanz = $checkboxtextsplit[1]
        $favorite = "F" & $checkboxtextsplit[2]
        $position = $checkboxtextsplit[3]

        ;Select actual Instance from Checkbox Name.
        If $instanz = "1" Then
            WinActivate($handle1)
        Else
            WinActivate($handle2)
        EndIf

        Send("{" & $favorite & "}")
        ;...
    EndIf
Next

Solution

  • I was providing GUICtrlRead() its parameters the wrong way. Instead of:

    If GUICtrlRead("$Checkbox" & $i, 0) = $GUI_CHECKED Then
        Local $checkboxtext = GUICtrlRead($Checkbox[$i], 1)
    

    It should be:

    If GUICtrlRead($Checkbox & $i, 0) = $GUI_CHECKED Then
        Local $checkboxtext = GUICtrlRead($Checkbox & $i, 1)
    

    To retrieve a Checkbox checked/un-checked state use:

    If GUICtrlRead($Checkbox & $i, 0) = $GUI_CHECKED Then ...
    

    To read text of a Checkbox use:

    $checkboxtext = GUICtrlRead($Checkbox & $i, 1)