Jump to content

Recommended Posts

Posted

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

Posted

Read in help file about _ArrayDelete() function. You can delete what element you want from your array.

Ohhh

Note to myself read the freaking manual ;-)

Thanks btw, works like a charm

Posted (edited)

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

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

 

Posted (edited)

#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

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

 

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
×
×
  • Create New...