Jump to content

Recommended Posts

Posted

I'm new to autoit. I know this is an easy question, but how do you delete an array and its values so it can be declared again with new values?

Posted (edited)

@danny0

Welcome to autoit forum :)

Example :

;Double array
Local $array[10][10]
$array[5][5] = "something"
MsgBox(64, "array", $array[5][5])
$array[5][5] = "" ;delete something to nothing
MsgBox(64, "array", $array[5][5])

;simple array
Local $array[10]
$array[5] = "something"
MsgBox(64, "array", $array[5])
$array[5] = "" ;delete something to nothing
MsgBox(64, "array", $array[5])

Cheers, FireFox.

Edited by FireFox
Posted (edited)

Hi and Welcome!

There are 2 ways.

- You declare an empty array and copy it to the one, you want to "delete". Or you can use ReDim.

Global $aEmpty[1]
Global $array[200] ; or size u want
;...
;...
$array = $aEmpty ; now is UBound($array) = 1 ==> an empty element

;=============================================
; with ReDim

ReDim $array[1]
$array[0] = ''
Edited by BugFix

Best Regards BugFix  

Posted

@danny0

Welcome to autoit forum :)

Example :

Local $array[10][10]
$array[5][5] = "something"
MsgBox(64, "array", $array[5][5])
$array[5][5] = "" ;delete something to nothing
MsgBox(64, "array", $array[5][5])

Cheers, FireFox.

Thanks! That worked great.
  • 1 year later...
Posted

To erase an array (maybe because it is a large global array and you want to free the memory), simply assign a single value to it:

$array = 0

That was quoted from the documentation.

http://www.autoitscript.com/autoit3/docs/keywords/Dim.htm

SAM

Posted (edited)

ReDim is not the answer. That changes the number of elements in the array, and only loses the existing data if you change the number of dimensions.

Setting the array variable to a non-array value, like $aArray = 0, will do it just fine.

But if you want the array to still exist, with the elements empty, then simply re-declare the array:

Global $aArray[10][10] ; original array

     ; Lots of stuff happens, lots of old data in array

Global $aArray[10][10] ; re-declare to empty (elements are all still there, but empty now)

     ; Continue to use freshly emptied array...

:(

Edited by PsaltyDS
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
  • 4 years later...
Posted (edited)

This is not enought. If you have custom functions with local arrays you dare to get trash from it.

This is the case in the usefull Call() calls, with a array as argument and 'CallArgArray' in array[0]. You will get all wrong.

Is needed wipe manually, example:

Func __CustomCall($sCadenaLlamada)
;[....]
   Local $aArgvs=StringSplit($sArgvs,',',1)
   Local $coder=$aArgvs[0]
   $aArgvs[0]='CallArgArray'
   $CallReturn=Call($sFuncName,$aArgvs)
   For $i=0 To $coder                  ; Wipe Array
      $aArgvs[$i]=Null
   Next
   If @error=0xDEAD Or @extended=0xBEEF Then
      $coder=0
   Else
      $coder=$CallReturn
   EndIf
;[....]
Return($coder)

Cheers.

Edited by zalomalo

My english shucks, i know it.

Posted (edited)

ReDim is not the answer.

 

Indeed, is Not enough.

Redeclare, neither.

Wipe it every component inside is the only way to not get unvalid old data if you dont know if $Array[0] is real and care of it.

Edited by zalomalo

My english shucks, i know it.

  • Moderators
Posted

zalomalo, did you not noticed that this thread is over 4 years old, and the OP hasn't been active in 5? Please don't resurrect old threads needlessly.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

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