Jump to content
Sign in to follow this  

Little Bug in _ArrayExtract

Recommended Posts



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.


; #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]
            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]
                Local $aRetArray[$iEnd_Row - $iStart_Row + 1][$iEnd_Col - $iStart_Col + 1]
            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]
                        $aRetArray[$i][$j] = $avArray[$i + $iStart_Row][$j + $iStart_Col]
            Return $aRetArray
        Case Else
            Return SetError(2, 0, -1)

    Return 1

EndFunc   ;==>_ArrayExtract

Share this post

Link to post
Share on other sites


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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:


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


Share this post

Link to post
Share on other sites


Thanks for the info.

Glad to be of help (although it wasnt this time)


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

Sign in to follow this  


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.