Jump to content

Multi-Dimensional Array _ArrayDelete


Recommended Posts

Hello,

Is it possible to delete a line from a Multi-Dimensional array???

_ArrayDelete( $avArray , 1 ) doesn't like it..

Doesn't say in the help file if it works with Multi-Dimensional Arrays :rolleyes:

I can't think how else to delete it.....

#include <Array.au3>

Dim $avArray[4][1]
$avArray[0][0] = "JPM"
$avArray[1][0] = "Holger"
$avArray[2][0] = "Jon"
$avArray[3][0] = "Larry"

_ArrayDisplay( $avArray, "Whole array" )

;Can Work on Multi-Dimensional?
_ArrayDelete( $avArray , 1 )

_ArrayDisplay( $avArray, "Removed entry" )
[font="Verdana"]Keith (Kogmedia)[/font]My ScriptQuick Search - Internet / Hard Drive Search
Link to comment
Share on other sites

Why not?

#include <Array.au3>

Dim $avArray[4][1]
$avArray[0][0] = "JPM"
$avArray[1][0] = "Holger"
$avArray[2][0] = "Jon"
$avArray[3][0] = "Larry"

_ArrayDisplay( $avArray, "Whole array" )

;!!! Delete those comented !!!
;Can Work on Multi-Dimensional?
;_ArrayDelete( $avArray , 1 )

$avArray[1][0] = "" ;Let's say we want to delete Holger
_ArrayDisplay( $avArray, "Removed entry" )

Not tested :rolleyes:

I can do signature me.

Link to comment
Share on other sites

I am trying to delete an empty array as i am using it to make a tray menu item and gives me -------- bar.

i.e -- TrayCreateItem("", $search, -1, 1)

did you test mine? here:

Tray menu:

"i542"

"-----" (the bar, here should be holger but we deleted him :rolleyes:)

"JdeB"

"Jon"

"Valik"

"jpm"

etc.

I can do signature me.

Link to comment
Share on other sites

Your demo arrays so far have not really been 2D array because there is only one effective subscript for each element: [n][0].

This demo puts some real 2D data in the array and shows my function for _ArrayDelete4D(), which will delete and element in an array with up to four subscripts (i.e. $Array[1][2][3][4]):

#include <Array.au3>

Dim $avArray[4][2]
$avArray[0][0] = "JPM"
$avArray[0][1] = "Red hair"
$avArray[1][0] = "Holger"
$avArray[1][1] = "Brown hair"
$avArray[2][0] = "Jon"
$avArray[2][1] = "Blonde hair"
$avArray[3][0] = "Larry"
$avArray[3][1] = "Black hair"

_ArrayDisplay($avArray, "Whole array")

;Can Work on Multi-Dimensional?
If _ArrayDelete4D ($avArray, 1) Then
    _ArrayDisplay($avArray, "Removed entry")
Else
    MsgBox(16, "Error", "_ArrayDelete4D returned 0 and @error = " & @error)
EndIf


Func _ArrayDelete4D(ByRef $avInput, $iElement)
    If (Not IsArray($avInput)) Or (Not IsInt($iElement)) Then Return SetError(1, 0, 0) ; Wrong type of input(s)
    
    Local $e, $f, $g, $h
    Local $avUbounds[UBound($avInput, 0) + 1] = [UBound($avInput, 0)]
    For $e = 1 to $avUbounds[0]
        $avUbounds[$e] = UBound($avInput, $e)
    Next
    If $avUbounds[0] > 4 Then Return SetError(2, 0, 0) ; Array has more than four subscripts
    If $avUbounds[1] = 1 Then Return SetError(3, 0, 0) ; Array only has one element
    If $iElement > $avUbounds[1] - 1 Or $iElement < 0 Then Return SetError(4, 0, 0) ; $iElement out of range
    If $iElement <> $avUbounds[1] - 1 Then
        For $e = $iElement To $avUbounds[1] - 2
            Switch $avUbounds[0]
                Case 1
                    $avInput[$e] = $avInput[$e + 1]
                Case 2
                    For $f = 0 To $avUbounds[2] - 1
                        $avInput[$e][$f] = $avInput[$e + 1][$f]
                    Next
                Case 3
                    For $f = 0 To $avUbounds[2] - 1
                        For $g = 0 To $avUbounds[3] - 1
                            $avInput[$e][$f][$g] = $avInput[$e + 1][$f][$g]
                        Next
                    Next
                Case 4
                    For $f = 0 To $avUbounds[2] - 1
                        For $g = 0 To $avUbounds[3] - 1
                            For $h = 0 To $avUbounds[4] - 1
                                $avInput[$e][$f][$g][$h] = $avInput[$e + 1][$f][$g][$h]
                            Next
                        Next
                    Next
            EndSwitch
        Next
    EndIf
    Switch $avUbounds[0]
        Case 1
            ReDim $avInput[$avUbounds[1] - 1]
        Case 2
            ReDim $avInput[$avUbounds[1] - 1][$avUbounds[2]]
        Case 3
            ReDim $avInput[$avUbounds[1] - 1][$avUbounds[2]][$avUbounds[3]]
        Case 4
            ReDim $avInput[$avUbounds[1] - 1][$avUbounds[2]][$avUbounds[3]][$avUbounds[4]]
    EndSwitch
    Return 1
EndFunc   ;==>_ArrayDelete3D

:rolleyes:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • 5 months later...

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