Jump to content

$GUI_UNCHECKED error with checkbox array


dumbfck
 Share

Recommended Posts

Hi there,

I've searched as much as I can but can't find a solution to this problem....

I have an array of checkboxes and within a function I am trying to check or uncheck each box...

Checking them using the $GUI_CHECKED constant works fine, but trying to uncheck them with the exact same code but with $GUI_UNCHECKED throws an error

==> Array variable subscript badly formatted.:
GUICtrlSetState($chkBox[$j], $GUI_UNCHECKED)
GUICtrlSetState($chkBox[^ ERROR

Here's the code in question, I can't for the life of me figure out what's going one....

Func getChatFilters()
    Local $chatFilterPtrList[7] = [0x00, 0x1C, 0x18, 0x8, 0x8C, 0x8, 0x218]
    $chatFilterPtr = _MemoryPointerRead($baseCall, $pHandle, $chatFilterPtrList)
    ConsoleWrite(@CRLF & Hex($chatFilterPtr[0]) & @CRLF)
    $filters = _MemoryRead($chatFilterPtr[0], $pHandle, "byte[79]")
    ConsoleWrite(Hex($filters) & @CRLF)
    
    for $x = 0 to $columns - 1
        for $y = 0 to $rows - 1
            $id = $x * $rows + $y
            ;ConsoleWrite(StringMid(Hex($filters), $id*2-1, 2) & @CRLF)
            Local $j = $id-1
            if StringMid(Hex($filters), $id*2-1, 2) = "01" Then
                GUICtrlSetState($chkBox[$j], $GUI_CHECKED)     ;This works
            Else
                GUICtrlSetState($chkBox[$j], $GUI_UNCHECKED)   ;This doesn't and throws an error
            EndIf
        Next
    Next
EndFunc

Any help would be hugely appreciated here, thanks in advance :mellow:

Link to comment
Share on other sites

hi guy, (yup I'm not going to type that nick)

On first iteration of the loop in your getChatFilters function, $x=0, $y=0, $id=0*rows+0 which is equal to 0 and $j=$id-1 which equals -1.

It follows that:

if StringMid(Hex($filters), $id*2-1, 2) = "01" Then
evaluates as
if StringMid(Hex($filters), -1, 2) = "01" Then

Since -1 is an invalid starting position parameter for the StringMid function, it returns an empty string which is not equal to "01" so it goes to the else part:

GUICtrlSetState($chkBox[$j], $GUI_UNCHECKED)
which evaluates as
GUICtrlSetState($chkBox[-1], $GUI_UNCHECKED)

A negative value for an array's index is invalid in AutoIt since the first location is 0, so it throws the very appropriate error message

Array variable subscript badly formatted

So yea, that's pretty much what's going on :mellow:

Try fixing your code so that only valid array indices are referenced, if you get stuck or need more help feel free to post back with your attempts :)

Hope this helps, :)

-smartee

lol. I coudn't help but notice the irony of smartee pointing out errors to someone named.. :)

Link to comment
Share on other sites

Ahhh *facepalm* you're completely right... I had fiddled with that equation for a while because it didn't seem to be starting at the first (0th) checkbox and everything was being offset by 1 checkbox. That -1 in the equation was my last desperate ditch attempt to realign it hehe... What I had forgotten was that Hex($Filters) returns a string starting with "0x".

Have changed it to

for $x = 0 to $columns - 1
        for $y = 0 to $rows - 1
            $id = $x * $rows + $y
            if StringMid(Hex($filters), $id*2+1, 2) = "01" Then
                GUICtrlSetState($chkBox[$id], $GUI_CHECKED)
            Else
                GUICtrlSetState($chkBox[$id], $GUI_UNCHECKED)
            EndIf
        Next
    Next

Thanks again for the help :)

lol. I coudn't help but notice the irony of smartee pointing out errors to someone named.. :)

That made me chuckle lol :mellow:

And sorry if the name causes offence... It's just kinda the name I got tagged with when doing this sort of work and it stuck :)

Edited by dumbfck
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...