Jump to content

UDF to do _ArrayDelete on Multi-Dim Array


 Share

Recommended Posts

Does anyone happen to have a UDF that will allow you to delete a row in an array with more than one column?

I can create a new array just a pain to do code everytime I need to do it.

Thanks,

Kenny

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

No problem :)

;----------------------------------------------------------------------------------------------------------------------
;   Fuction         _Array2DDelete(ByRef $ARRAY, $iDEL, $bCOL=False)
;
;   Description     Delete one row on a given index in an 1D/2D -Array
;
;   Parameter       $ARRAY      the array, where one row will deleted
;                   $iDEL       Row(Column)-Index to delete
;                   $bCOL       If True, delete column instead of row (default False)
;  
;   Return          Succes      0   ByRef $ARRAY
;                   Failure     1   set @error = 1; given array are not array
;                                   set @error = 2; want delete column, but not 2D-array
;                                   set @error = 3; index is out of range
;
; Author            BugFix (bugfix@autoit.de)
;----------------------------------------------------------------------------------------------------------------------
Func _Array2DDelete(ByRef $ARRAY, $iDEL, $bCOL=False)
    If ( Not IsArray($ARRAY) ) Then Return SetError(1,0,1)
    Local $UBound2nd = UBound($ARRAY,2), $k
    If $bCOL Then 
        If $UBound2nd = 0 Then Return SetError(2,0,1)
        If ( $iDEL < 0 ) Or ( $iDEL > $UBound2nd-1 ) Then Return SetError(3,0,1)
    Else
        If ( $iDEL < 0 ) Or ( $iDEL > UBound($ARRAY)-1 ) Then Return SetError(3,0,1)
    EndIf
    If $UBound2nd = 0 Then
        Local $arTmp[UBound($ARRAY)-1]
        $k = 0
        For $i = 0 To UBound($ARRAY)-1
            If $i <> $iDEL Then 
                $arTmp[$k] = $ARRAY[$i]
                $k += 1
            EndIf
        Next
    Else
        If $bCOL Then
            Local $arTmp[UBound($ARRAY)][$UBound2nd-1]
            For $i = 0 To UBound($ARRAY)-1
                $k = 0
                For $l = 0 To $UBound2nd-1
                    If $l <> $iDEL Then
                        $arTmp[$i][$k] = $ARRAY[$i][$l]
                        $k += 1
                    EndIf
                Next
            Next
        Else
            Local $arTmp[UBound($ARRAY)-1][$UBound2nd]
            $k = 0
            For $i = 0 To UBound($ARRAY)-1
                If $i <> $iDEL Then
                    For $l = 0 To $UBound2nd-1
                        $arTmp[$k][$l] = $ARRAY[$i][$l]
                    Next
                    $k += 1
                EndIf
            Next
        EndIf
    EndIf
    $ARRAY = $arTmp
    Return 0
EndFunc ;==>_Array2DDelete

Best Regards BugFix  

Link to comment
Share on other sites

beautiful, thanks alot!! :)

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

Just wanted to say it worked perfectly :)

Thanks again,

Kenny

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

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