Jump to content

Possible bug: _ArrayFindAll


Recommended Posts

$avResult "array variable has incorrect number of subscripts..." error appears in _ArrayFindAll when function used in example below:
#include <Array.au3>
Global $array[1][3] = [["a", "b", "a"]]
_ArrayDisplay (_ArrayFindAll ($array, "a", 0, 0, 0, 0, 0, true))
Should be like this I believe. Change in line "$avResult[uBound($avArray, $bRow + 1)]", originally was "$avResult[uBound($avArray)]":
Func _ArrayFindAll(Const ByRef $avArray, $vValue, $iStart = 0, $iEnd = 0, $iCase = 0, $iCompare = 0, $iSubItem = 0, $bRow = False)

If $iStart = Default Then $iStart = 0
If $iEnd = Default Then $iEnd = 0
If $iCase = Default Then $iCase = 0
If $iCompare = Default Then $iCompare = 0
If $iSubItem = Default Then $iSubItem = 0
If $bRow = Default Then $bRow = False

$iStart = _ArraySearch($avArray, $vValue, $iStart, $iEnd, $iCase, $iCompare, 1, $iSubItem, $bRow)
If @error Then Return SetError(@error, 0, -1)

Local $iIndex = 0, $avResult[UBound($avArray, $bRow + 1)]
Do
$avResult[$iIndex] = $iStart
$iIndex += 1
$iStart = _ArraySearch($avArray, $vValue, $iStart + 1, $iEnd, $iCase, $iCompare, 1, $iSubItem, $bRow)
Until @error

ReDim $avResult[$iIndex]
Return $avResult
EndFunc   ;==>_ArrayFindAll

If so, worth creating new ticket as I haven't find similar one posted earlier and bug persists in beta, unfrotunately my IP has been banned by Trac.

Link to comment
Share on other sites

  • Moderators

1st, ArrayDisplay requires a variable to be passed.  Notice that the first parameter is "ByRef".

2nd, that function looks crazy... nothing like I'd expect the results to be provided.  Not sure if I like that it only deals with this in a 1D type of manner even though it attempts to work with 2D as well.

See if this works:

Func _ArrayFindAll_(Const ByRef $avArray, $vValue, $iStart = 0, $iEnd = 0, $iCase = 0, $iCompare = 0, $iSubItem = 0, $bRow = False)

    If $iStart = Default Then $iStart = 0
    If $iEnd = Default Then $iEnd = 0
    If $iCase = Default Then $iCase = 0
    If $iCompare = Default Then $iCompare = 0
    If $iSubItem = Default Then $iSubItem = 0
    If $bRow = Default Then $bRow = False

    Local $avResult[UBound($avArray)], $iIndex = -1, $iErr
    $iStart -= 1
    For $i = 0 To UBound($avResult) - 1
        $iStart = _ArraySearch($avArray, $vValue, $iStart + 1, $iEnd, $iCase, $iCompare, 1, $iSubItem, $bRow)
        $iErr = @error
        If $iErr Then ExitLoop
        $iIndex += 1
        $avResult[$iIndex] = $iStart
    Next

    If $iIndex = -1 Then Return SetError($iErr, 0, 0)

    ReDim $avResult[$iIndex + 1]
    Return $avResult
EndFunc

.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

1st, ArrayDisplay requires a variable to be passed.  Notice that the first parameter is "ByRef".

2nd, that function looks crazy... nothing like I'd expect the results to be provided.  Not sure if I like that it only deals with this in a 1D type of manner even though it attempts to work with 2D as well.

1) Well, I attempt to display array of indices that have been found, not array itself.

2) Nope, it shows [0], but should be [0, 2], i.e. first and last index in 2D array with one row and three columns. But slightly modified function I posted above works :)

Edited by mjolnirmarkiv
Link to comment
Share on other sites

  • Moderators

mjolnirmarkiv,

Nice catch as usual - thanks for the report, and the solution. :thumbsup:

I will amend the function for the next release. :)

M23

And done - in a slightly different way:

Local $iIndex = 0, $avResult[UBound($avArray, (($bRow)?($UBOUND_COLUMNS):($UBOUND_ROWS)))] ; Set dimension for Column/Row
Edited by Melba23

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

  • 4 months later...

Sorry Melba, I believe we were getting a random commented out ";_ArrayDisplay($avResult, $aUniqueHostname[$i01])" to pop up for some reason after an Local $avResult = _ArrayFindAll($array01, $aUniqueHostname[$i01], 0, 0, 0, 0, 1) No idea why. You can delete this message if you like.

Edited by souldjer777

"Maybe I'm on a road that ain't been paved yet. And maybe I see a sign that ain't been made yet"
Song Title: I guess you could say
Artist: Middle Class Rut

Link to comment
Share on other sites

  • Moderators

souldjer777,

Your post above makes no sense to me at all - what relationship is there between the dialog you posted and the earlier bug in _ArrayFindAll?

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

Only slightly off topic.  And there are many ways to compare arrays, and many different meanings and results that a user could want from a comparison (of which a visual windiff is probably not super extensible).  There are some other examples here:

Cleaned up my effort:

#include <Array.au3>

Global $aCompare1[10] = [1, 3, 5, 6, 7, 8, 9, 10, 11, 12]
Global $aCompare2[10] = [1, 2, 3, 4, 5, 6, 8, 10, 12, 13]

$aFinalComp = _ArrayCompare($aCompare1 , $aCompare2)

_ArrayDisplay($aFinalComp[0] , 'In Both Arrays')
_ArrayDisplay($aFinalComp[1] , 'Only In First Array')
_ArrayDisplay($aFinalComp[2] , 'Only In Second Array')


Func _ArrayCompare($aArray1 , $aArray2)

Local $aBoth[0]
Local $aOut[3]

For $i = ubound($aArray1) - 1 to 0 step -1
$iMatch = _ArraySearch($aArray2 , $aArray1[$i])
If $iMatch <> -1 then
    _ArrayAdd($aBoth , $aArray1[$i])
    _ArrayDelete($aArray1 , $i)
    _ArrayDelete($aArray2, $iMatch)
EndIf
Next

For $i = ubound($aArray2) - 1 to 0 step -1
$iMatch = _ArraySearch($aArray1 , $aArray2[$i])
If $iMatch <> -1 then
    _ArrayAdd($aBoth , $aArray2[$i])
    _ArrayDelete($aArray2 , $i)
    _ArrayDelete($aArray1 , $iMatch)
EndIf
Next

$aOut[0] = $aBoth
$aOut[1] = $aArray1
$aOut[2] = $aArray2

return $aOut

EndFunc

 

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

  • Moderators

souldjer777,

I have checked the 3.3.12.0 and 3.3.13.20 Array libraries and there are no additional _ArrayDisplay calls within their _ArrayFindAll functions  - I can only imagine you were using a previously posted Alpha version of the function which still had some debugging code within it.

antonioj84,

Did anyone ask for an _ArrayCompare function when I was looking for input during the Array library rewrite? And as boththose has mentioned, there are so many possible array formats and comparison options that I feel it would be difficult to produce a function which satisfied enough people and was still maintainable by our very small team of volunteers. So I am not at all sure that we would have entertained the idea in any case.

And please do not hijack threads - just open a new one next time.

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

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