Jump to content

How to delete a specific element in multi dimensional array


Recommended Posts

Hi

Just started with AutoIt but having problems with my arrays

Im trying to delete an element from my multi dimensional array

My array looks like this

Global $valleyarr[1][5] = [[0, 0, 0, 0, 0]]

After adding some elements my array lets say I have 5 elements and what to delete the 3.

I've trid everything with redim but cant figure it out.

Code

if $valleyarr[$i][4] then

ReDim $valleyarr[$i][5]

endif

But it seems to delete my whole array

i want to remove that specific element

Link to comment
Share on other sites

Hi

Just started with AutoIt but having problems with my arrays

Im trying to delete an element from my multi dimensional array

My array looks like this

Global $valleyarr[1][5] = [[0, 0, 0, 0, 0]]

After adding some elements my array lets say I have 5 elements and what to delete the 3.

I've trid everything with redim but cant figure it out.

Code

if $valleyarr[$i][4] then

ReDim $valleyarr[$i][5]

endif

But it seems to delete my whole array

i want to remove that specific element

#include <Array.au3>
Global $myArray[3][5] = [[1, 2, 3, 4, 5],[6, 7, 8, 9, 10],[11, 12, 13, 14, 15]]

_ArrayDisplay($myArray, "myArray")
$myArray = Element_Array_Delete($myArray,"0|1","0|1")
_ArrayDisplay($myArray, "OutArray")


Global $myArray[5] = [1, 2, 3, 4, 5]

_ArrayDisplay($myArray, "myArray")
$myArray = Element_Array_Delete($myArray,"0|1")
_ArrayDisplay($myArray, "OutArray")



Func Element_Array_Delete($Array,$RowsiElement = "",$ColsiElement = "")
if Not IsArray($Array) Then Return -1
$rows = UBound($Array) - 1
$cols = UBound($Array, 2) - 1
$IB = 0
$StrArray1 = StringSplit($RowsiElement, "|")
$StrArray2 = StringSplit($ColsiElement, "|")
Select
Case UBound($Array, 2) <> 0
Local $OutArray[1][1]

For $IA = 0 To $rows Step 1
$BOOL = False
For $i = 1 To $StrArray1[0]
if StringCompare($StrArray1[$I], String($IA)) = 0 Then
$BOOL = True
ExitLoop
EndIf
Next
If ($BOOL) Then ContinueLoop

$IB += 1
$JB = 0
For $JA = 0 To $cols Step 1
$BOOL = False
For $i = 1 To $StrArray2[0]
if StringCompare($StrArray2[$I], String($JA)) = 0 Then
$BOOL = True
ExitLoop
EndIf
Next
If ($BOOL) Then ContinueLoop

$JB += 1
if (UBound($OutArray, 2) - 1) < $JB Then
ReDim $OutArray[$IB][$JB]
$OutArray[$IB - 1][$JB - 1] = $Array[$IA][$JA]
Else
ReDim $OutArray[$IB][UBound($OutArray, 2)]
$OutArray[$IB - 1][$JB - 1] = $Array[$IA][$JA]
EndIf

Next
Next

Case UBound($Array, 2) = 0
Local $OutArray[1] , $IB = 0

For $IA = 0 To $rows Step 1
$BOOL = False
For $i = 1 To $StrArray1[0]
if StringCompare($StrArray1[$I], String($IA)) = 0 Then
$BOOL = True
ExitLoop
EndIf
Next
If ($BOOL) Then ContinueLoop

$IB += 1
ReDim $OutArray[$IB]
$OutArray[$IB - 1] = $Array[$IA]
Next

EndSelect
Return $OutArray
EndFunc
Edited by wolf9228

صرح السماء كان هنا

 

Link to comment
Share on other sites

#include <Array.au3>
Global $myArray[3][5] = [[1, 2, 3, 4, 5],[6, 7, 8, 9, 10],[11, 12, 13, 14, 15]]

_ArrayDisplay($myArray, "myArray")
$myArray = Element_Array_Delete($myArray,"0|1","0|1")
_ArrayDisplay($myArray, "OutArray")


Global $myArray[5] = [1, 2, 3, 4, 5]

_ArrayDisplay($myArray, "myArray")
$myArray = Element_Array_Delete($myArray,"0|1")
_ArrayDisplay($myArray, "OutArray")



Func Element_Array_Delete($Array,$RowsiElement = "",$ColsiElement = "")
if Not IsArray($Array) Then Return -1
$rows = UBound($Array) - 1
$cols = UBound($Array, 2) - 1
$IB = 0
$StrArray1 = StringSplit($RowsiElement, "|")
$StrArray2 = StringSplit($ColsiElement, "|")
Select
Case UBound($Array, 2) <> 0
Local $OutArray[1][1]

For $IA = 0 To $rows Step 1
$BOOL = False
For $i = 1 To $StrArray1[0]
if StringCompare($StrArray1[$I], String($IA)) = 0 Then
$BOOL = True
ExitLoop
EndIf
Next
If ($BOOL) Then ContinueLoop

$IB += 1
$JB = 0
For $JA = 0 To $cols Step 1
$BOOL = False
For $i = 1 To $StrArray2[0]
if StringCompare($StrArray2[$I], String($JA)) = 0 Then
$BOOL = True
ExitLoop
EndIf
Next
If ($BOOL) Then ContinueLoop

$JB += 1
if (UBound($OutArray, 2) - 1) < $JB Then
ReDim $OutArray[$IB][$JB]
$OutArray[$IB - 1][$JB - 1] = $Array[$IA][$JA]
Else
ReDim $OutArray[$IB][UBound($OutArray, 2)]
$OutArray[$IB - 1][$JB - 1] = $Array[$IA][$JA]
EndIf

Next
Next

Case UBound($Array, 2) = 0
Local $OutArray[1] , $IB = 0

For $IA = 0 To $rows Step 1
$BOOL = False
For $i = 1 To $StrArray1[0]
if StringCompare($StrArray1[$I], String($IA)) = 0 Then
$BOOL = True
ExitLoop
EndIf
Next
If ($BOOL) Then ContinueLoop

$IB += 1
ReDim $OutArray[$IB]
$OutArray[$IB - 1] = $Array[$IA]
Next

EndSelect
Return $OutArray
EndFunc

Edited by wolf9228

صرح السماء كان هنا

 

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