Jump to content

Error handling


makogen
 Share

Recommended Posts

Ok, I've run into a bit of a problem:

In my original code I had a gui with 60 editable buttons kinda like a type it in clone. you click one and it writes what you want it to say. The buttons are made from a 2 diminsional array that contains the data on each button like font color, location, color, and also the context menu.

I decided to try to rewite the code so there aren't over 200 cases in the select. And I'm using a variation of the _ArraySearch function I found in the forums, the _ArraySearchAnyDim. Here's a little of what the code looks like:

While 1

        $i = 0
        $msg = GUIGetMsg()
;~      ConsoleWrite($msg & @CRLF)
        Select
            Case $msg = $GUI_EVENT_CLOSE
                Exit
                
            Case $msg > 0
                
                $pos = _ArraySearchAnyDim($respBtns, $msg, 0, 0, 0, "[x][7]");refs to control ID (what button was clicked)
                $pos2 = _ArraySearchAnyDim($respBtns, $msg, 0, 0, 0, "[x][9]");refs to context menu:EDIT
;~              $pos3 = _ArraySearchAnyDim($respBtns, $msg, 0, 0, 0, "[x][10]");refs to context menu:
;~              $pos4 = _ArraySearchAnyDim($respBtns, $msg, 0, 0, 0, "[x][11]");refs to context menu:
                
                
                
                If $msg = $respBtns[$pos][7] Then
                    MsgBox(0,"error",@error)
                    
                    If @error Then
                        SetError(0)
                    EndIf
                    MsgBox(0, $msg, $pos)
                EndIf
            
            If $msg = $respBtns[$pos2][9] Then
                    
                    If @error Then
                        SetError(0)
                    EndIf
                    MsgBox(0, $msg, $pos2)
                EndIf
            ;;;
        EndSelect
        
    WEnd

Everytime I click a button, it checks both $pos and $pos2 and gives me an error on the array being badly formatted. I understand why the error is coming, but I can't seem to get around it. Is there a way to catch the error and allow the program to continue running?

Something like If there's an error, then skip the block

Please any help would be great, I'm new to error handling and any references would be great as well :) thanx

Link to comment
Share on other sites

I couldn't find any such function as _ArraySearchAnyDim in my AutoIt installation folder. Probably you found it on the forums. There is likely no problem with the function and instead, your array is badly formatted, just like the error states, and it is a function that is called within that function that is throwing the error. There is no way to keep the error from occurring but by fixing the array, likely business.

In the beta include file, there is a handy function called _ArrayDisplay. To discover the contents of the array, you could trying using it in your code to check the contents of the array just before where you first call _ArraySearchAnyDim. But that might just throw the same error. Review the code you used to build your array in the first place, and fix it.

And given the provided code, any time a button is clicked, all instances of _ArraySearchAnyDim are called, one after another because they are listed there one after another right after the Case > 0 statement.

Edited by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

:) thanks I figure it out ;) this is what i got :D

$rpos = _ArraySearchAnyDim($rBtns, $msg, 0, 0, 0, "[x][7]");refs to control ID (what button was clicked)
                If $rpos > -1 Then
                    
                    If $msg = $rBtns[$rpos][7] Then
                        
;~                      MsgBox(0, $rpos, "works")
                    EndIf


                ElseIf $rpos == -1 Then
                    
                    $rpos2 = _ArraySearchAnyDim($rBtns, $msg, 0, 0, 0, "[x][9]");refs to context menu:EDIT
                    If $rpos2 > -1 Then

                        If $msg = $rBtns[$rpos2][9] Then
                            MsgBox(0, $msg, $rpos2)
                            EndIf

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