Jump to content

Cool 1o2 Dimension Array Row Deleter Script


ozone
 Share

Recommended Posts

Ever had a row in an array you wanted deleted? Well here is the script for you.

Func Name = delete_array_row

Variables:

$array = name of your array

$dimcount = dimensions of array (can be either 1 or 2)

$row = row # you want deleted

Dim $array[10][2]

For $i = 0 to UBound($array, 1) - 1
    If $i = 4 Then delete_array_row($array, 2, 5);line which deletes a row
    MsgBox(1,"", $array[$i][1])
    If $i = UBound($array, 1) - 1 Then ExitLoop(1);exists loop if new end bounds is reached
Next

Func delete_array_row(ByRef $array, $dimcount, $row)
    If $dimcount = 2 Then
        Dim $temp[UBound($array,1)-1][UBound($array,2)]
        For $a = 0 to $row-1
            For $b = 0 to UBound($array,2) - 1
                $temp[$a][$b] = $array[$a][$b]
            Next
        Next
        For $a = $row+1 to UBound($array,1) - 1
            For $b = 0 to UBound($array,2) - 1
                $temp[$a-1][$b] = $array[$a][$b]
            Next
        Next
        $array = $temp
        Return
    Else
        Dim $temp[UBound($array,1) - 1]
        For $a = 0 to $row-1
            $temp[$a] = $array[$a]
        Next
        For $a = $row+1 to UBound($array,1) - 1
            $temp[$a-1] = $array[$a]
        Next
        $array = $temp
        Return
    EndIf
EndFunc

Don't forget the "If $i = UBound($array, 1) - 1 Then ExitLoop(1)" line, because if you set the end of the For loop to the UBound of the array, that value is not "re-calculated" when you delete a row. So this line will factor that in. Suggestions welcome. :)

Edited by ozone
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...