-1

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
Sardar Agabejli
  • 423
  • 8
  • 32
  • 1
    "*Does AutoIt increment the $i variable automatically?*" [Yes](https://www.autoitscript.com/autoit3/docs/keywords/For.htm). – user4157124 Sep 28 '17 at 18:37

1 Answers1

0

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)
user4157124
  • 2,809
  • 13
  • 27
  • 42
Sardar Agabejli
  • 423
  • 8
  • 32