momar33 Posted September 28, 2015 Posted September 28, 2015 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 & ".") EndIfAny help would be appreciated.Thanks,momar33
jguinch Posted September 28, 2015 Posted September 28, 2015 (edited) @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 September 28, 2015 by jguinch Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
kaisies Posted September 28, 2015 Posted September 28, 2015 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now