Jump to content

Little Bug in _ArrayExtract


Go to solution Solved by Melba23,

Recommended Posts

Hi,

i found and corrected a little bug in _ArrayExtract. The function is not working correctly with 0-based 2 dim arrays. This is due to the fact that the parameter default is '0' but should be 'Default' - as 0 is a valid option for the function call. Here is my corrected version - if you make use of it - helpfile and function tips have to be adapted.

Cheers.

; #FUNCTION# ====================================================================================================================
; Author ........: Melba23
; Modified.......:
; ===============================================================================================================================
Func _ArrayExtract(Const ByRef $avArray, $iStart_Row = Default, $iEnd_Row = Default, $iStart_Col = Default, $iEnd_Col = Default)

    If $iStart_Row = Default Then $iStart_Row = 0
    If $iStart_Col = Default Then $iStart_Col = 0
    ;removed as this is not working with 0-based arrays
    ;If $iEnd_Row = Default Then $iEnd_Row = 0
    ;If $iEnd_Col = Default Then $iEnd_Col = 0

    If Not IsArray($avArray) Then Return SetError(1, 0, -1)
    Local $iDim_1 = UBound($avArray, $UBOUND_ROWS) - 1
    If $iEnd_Row = Default Then $iEnd_Row = $iDim_1
    If $iStart_Row < 0 Or $iEnd_Row < 0 Then Return SetError(3, 0, -1)
    If $iStart_Row > $iDim_1 Or $iEnd_Row > $iDim_1 Then Return SetError(3, 0, -1)
    If $iStart_Row > $iEnd_Row Then Return SetError(4, 0, -1)
    Switch UBound($avArray, $UBOUND_DIMENSIONS)
        Case 1
            Local $aRetArray[$iEnd_Row - $iStart_Row + 1]
            For $i = 0 To $iEnd_Row - $iStart_Row
                $aRetArray[$i] = $avArray[$i + $iStart_Row]
            Next
            Return $aRetArray
        Case 2
            Local $iDim_2 = UBound($avArray, $UBOUND_COLUMNS) - 1
            If $iEnd_Col = Default Then $iEnd_Col = $iDim_2
            If $iStart_Col < 0 Or $iEnd_Col < 0 Then Return SetError(5, 0, -1)
            If $iStart_Col > $iDim_2 Or $iEnd_Col > $iDim_2 Then Return SetError(5, 0, -1)
            If $iStart_Col > $iEnd_Col Then Return SetError(6, 0, -1)
            If $iStart_Col = $iEnd_Col Then
                Local $aRetArray[$iEnd_Row - $iStart_Row + 1]
            Else
                Local $aRetArray[$iEnd_Row - $iStart_Row + 1][$iEnd_Col - $iStart_Col + 1]
            EndIf
            For $i = 0 To $iEnd_Row - $iStart_Row
                For $j = 0 To $iEnd_Col - $iStart_Col
                    If $iStart_Col = $iEnd_Col Then
                        $aRetArray[$i] = $avArray[$i + $iStart_Row][$j + $iStart_Col]
                    Else
                        $aRetArray[$i][$j] = $avArray[$i + $iStart_Row][$j + $iStart_Col]
                    EndIf
                Next
            Next
            Return $aRetArray
        Case Else
            Return SetError(2, 0, -1)
    EndSwitch

    Return 1

EndFunc   ;==>_ArrayExtract
Link to comment
Share on other sites

  • Moderators
  • Solution

poolcat,

Already reported and fixed in the latest Beta - but thanks for taking the time to post about it. :)

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