Jump to content
momar33

ArraySearch Not Returning Error

Recommended Posts

momar33

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

 

Share this post


Link to post
Share on other sites
jguinch

@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

Share this post


Link to post
Share on other sites
kaisies

I'm not a @error expert, but I believe this is because you have a array display after the search. Which is resetting @error to zero. Try commenting that out 

Share this post


Link to post
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

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.