Sign in to follow this  
Followers 0
danny0

Easy Array Question

11 posts in this topic

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?

Share this post


Link to post
Share on other sites



#2 ·  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

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

#3 ·  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  

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#6 ·  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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Redim $array[0]

Share this post


Link to post
Share on other sites

#9 ·  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.

Share this post


Link to post
Share on other sites

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.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Sorry, my fault. Im silly.


My english shucks, i know it.

Share this post


Link to post
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
Sign in to follow this  
Followers 0