Jump to content

_ArraySearch Not returning expected value.


cal
 Share

Recommended Posts

_ArraySearch on a 2D array.

The help file says it returns the index of where the value was found. It should return a -1 if not found and set the error code.

If found its working as expected, but if not found it sets the error code fine but its returning a 1 instead of a -1. I can work around it now that I know whats going on. Just wondering if this a known issue or perhaps something on my side.

Link to comment
Share on other sites

  • Moderators

cal,

There is nothing in the _ArraySearch code to suggest that it would ever return with @error set and 1 as the return value - all the Return SetError lines use -1. ;)

Could you let us see an array which gives you the problem - and the basic code you are using as well, of course. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Yep. my side.

Creating separate code made me realize what I was doing.

Test Code below.

Note that the error is 6 as it should be.

Note that my message boxes are formatted with dashes. Its an expansion from typing mb that I use a lot. Helps detecting beginning and trailing spaces but here it made me think the -1 was a 1. ;)

But the true mistake was in my "if" statements. I has assumed that a -1 would not trigger the "if" statements to run. It does. If I change it to put the "> 0 " part in like the second "if" statement then it works as expected.

I modified the original codes "IF" statements and it now works.

$ver = 'ver 1w'
#Tidy_Parameters = /Skip_EndRegion_Comment

If Not @Compiled Then Opt("TrayIconDebug", 1) ;0=no info, 1=debug line info
Opt("MouseCoordMode", 0) ;1=absolute, 0=relative
Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced
FileChangeDir(@ScriptDir)

#Include <Array.au3>
;~ #include <_array_display_expand.au3>


; ensure this copy is the running one.
$g_szVersion = "test Script"
If WinExists($g_szVersion) Then WinClose($g_szVersion)
AutoItWinSetTitle($g_szVersion)

HotKeySet("{ESC}", "Terminate")
Func Terminate()
    Exit 0
EndFunc   ;==>Terminate


Dim $a[2][2]
$a[0][0] = 'up left'
$a[0][1] = 'up right'
$a[1][0] = 'bottom left'
$a[1][1] = 'bottom right'


;~ _ArrayDisplayExpanded($a ,'Line ' & @ScriptLineNumber & ' --- ' & '')
_ArrayDisplay($a)


$t = _ArraySearch($a, 'site/down', 0, 0, 0, 1, 1, 0)
MsgBox(0,'Line ' & @ScriptLineNumber, '---' & @error & '---')
MsgBox(0,'Line ' & @ScriptLineNumber, '---' & $t & '---')

If _ArraySearch($a, 'site/down', 0, 0, 0, 1, 1, 0) then MsgBox(0,'Line ' & @ScriptLineNumber, '--- found ---')
If _ArraySearch($a, 'site/down', 0, 0, 0, 1, 1, 0) > 0 then MsgBox(0,'Line ' & @ScriptLineNumber, '--- found take two ---')
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...