Jump to content

ArraySearch Not Returning Error


momar33
 Share

Recommended Posts

When doing a search for a value that is not in the array, I am not getting an error.

Instead it returns -1 as the index that it was found in.

From some searching I noticed that this used to be an issue when using different variable types, but in my example all variables are strings.

Here is the example:

#include <Array.au3>
#include <MsgBoxConstants.au3>

Global $aSavedFiles[] = ["test", _
                        "dd_TESTCL_private.m", _
                        "dd_TESTCL_protected.m", _
                        "dd_TRSTAT_private.m", _
                        "OBJECT_TESTCL.mdl", _
                        "PUBLIC__T_TESTACTV.m", _
                        "PUBLIC__T_TESTEVT.m", _
                        "PUBLIC__T_TSTSTATTTRV.m", _
                        "TESTCL__CTRV.mdl", _
                        "TESTCL__SELECT.mdl", _
                        "TESTCL__T_STTTRV.m", _
                        "TESTCL__TTRV.mdl"]


_ArraySort($aSavedFiles, Default, 1)

$iIndex = _ArraySearch($aSavedFiles, "TRSTAT__TLASTAT.mdl")
;$iIndex = _ArrayBinarySearch($aSavedFiles, "TRSTAT__TLASTAT.mdl")
;ConsoleWrite("IndexFound = " & $iIndex & @CRLF)

_ArrayDisplay($aSavedFiles)

If @error Then
    MsgBox($MB_SYSTEMMODAL, "Not Found", '"' & "TRSTAT__TLASTAT.mdl" & '" was not found in the array.')
Else
    MsgBox($MB_SYSTEMMODAL, "Found", '"' & "TRSTAT__TLASTAT.mdl" & '" was found in the array at position ' & $iIndex & ".")
EndIf

Any help would be appreciated.

Thanks,
momar33

 

Link to comment
Share on other sites

@error is relative to the previous execution.

In you example, @error is set to 0 by _ArrayDisplay. You have to perform the @error check just after _ArraySort.

Try to remove (comment) the _ArrayDisplay line

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