Jump to content

Easy Array Question


 Share

Recommended Posts

@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
Link to comment
Share on other sites

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  

Link to comment
Share on other sites

  • 1 year later...

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 4 years later...

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • Moderators

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!

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