Sign in to follow this  
Followers 0
hezi

clearing Array

6 posts in this topic

is there fast and nice way to clear array? (clear all elements and probably free some memory....)

i can loop to delete element until end but i look for more elegant way :)

maybe delete and recreate array (if possible didnt find this option)

thanks!

Share this post


Link to post
Share on other sites



hezi,

Just redeclare the array and it is emptied for you: :)

#include <Array.au3>

Global $aArray[3] = [1, 2, 3]

_ArrayDisplay($aArray)

Global $aArray[3]

_ArrayDisplay($aArray)

If you want to get rid of the array completely, just declare it as a simple variable - $aArray = 0. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post


Link to post
Share on other sites

Cool !

thanks for quick reply!

Thanks Melba23

Share this post


Link to post
Share on other sites

Another approach that will pass the Au3Check with advanced parameters >>

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#include <Array.au3>

Global $aArray[3] = [1, 2, 3]
Global $aBackup[UBound($aArray)] ; Create a blank array.

_ArrayDisplay($aArray)

$aArray = $aBackup

_ArrayDisplay($aArray)

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Or another way is this >>

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#include <Array.au3>

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

_ArrayDisplay($a1D)

_ArrayClear($a1D)

_ArrayDisplay($a1D)

Func _ArrayClear(ByRef $aArray)
    Local $iCols = UBound($aArray, 2)
    Local $iDim = UBound($aArray, 0)
    Local $iRows = UBound($aArray, 1)
    If $iDim = 1 Then
        Local $aArray1D[$iRows]
        $aArray = $aArray1D
    Else
        Local $aArray2D[$iRows][$iCols]
        $aArray = $aArray2D
    EndIf
EndFunc   ;==>_ArrayClear

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

thanks guinness!

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

  • Similar Content

    • FMS
      decrypted array don't match ctrl-read
      By FMS
      Hello,
      I don't know whats wrong whit this picture
      I've a encrypted and decrypted array called $usernames  (this was whit _Crypt_EncryptData)
      if ubound($userNames)> 0 then for $i = 0 to ubound($usernames)-1 If $usernames[$i] = GUICtrlRead($combo_usr_select) Then consolewrite("YES " & $i & " = " & $usernames[$i] & " | ctr = " & GUICtrlRead($combo_usr_select)) Else consolewrite("NO " & $i & " = " & $usernames[$i] & " | ctr = " & GUICtrlRead($combo_usr_select)) EndIf next EndIf When i try to look up the GUICtrlRead($combo_usr_select) in this array he can't find it :S
      in every case the consolewrite say's NO instead of YES when $usernames[$i] And GUICtrlRead($combo_usr_select) are equal.
      Did i do something wrong ???
      please advice and thanks in advanced.
       
    • OMGWTFLOLBBQ
      Text to Array
      By OMGWTFLOLBBQ
      Hello!
       I've been going through all of the help files and examples, but I feel lost. I can't seem to find what I need. Essentially, what I'm doing is simple(in my head).
      Create a file based on the information needed, select a line in that file, then put that line back in DOS. My code is below, I know it's messy, but I'll take the heat if you can help.
       
      ;BitlockerUpdate ;2016.05.24 HotKeySet("{ESC}", "Terminate") Run("C:\Windows\System32\CMD.exe") ;open command prompt Sleep(500) ;sleep half second if ProcessExists("cmd.exe") Then winactivate("Administrator: C:\Windows\System32\CMD.exe") ;refocus command prompt Send("C:") Send("{ENTER}") send("CD{SPACE}%windir%\sysnative\") send("{ENTER}") EndIf ;create file with Bitlocker Protectors Send("manage-bde.exe{SPACE}-protectors{SPACE}-get{space}c:{space}>{Space}%userprofile%\Desktop\protectors.txt") ;send code "manage-bde -protectors -get c: > %userprofile%\Desktop\protectors.txt" Send("{ENTER}") ;send enter key to create text file on desktop with protectors Sleep(1000) ;sleep one second(1s) ;edit txt file/create array, pull line and paste into new file, copy text then paste into cmd window below ;update data if ProcessExists("cmd.exe") Then winactivate("Administrator: C:\Windows\System32\CMD.exe") ;refocus command prompt Send("manage-bde.exe{SPACE}-protectors{SPACE}-adbackup{SPACE}c:{SPACE}-id{SPACE}{COPIEDINFORMATIONGOESHERE}") Send("{ENTER}") ;don't forget to delete temp file if you create one created. EndIf ;remove files if ProcessExists("cmd.exe") Then winactivate("Administrator: C:\Windows\System32\CMD.exe") ;refocus command prompt Send("DEL{SPACE}%userprofile%\Desktop\protectors.txt") ;send code to delete protectors.txt Send("{ENTER}") ;don't forget to delete temp file if you create one created. EndIf MsgBox(0,"Done","Copy and upload are done. Please check Computer in AD.") Func Terminate() Exit 0 EndFunc  
      The protectors.txt file looks like this:
      BitLocker Drive Encryption: Configuration Tool version 6.1.7601 Copyright (C) Microsoft Corporation. All rights reserved. Volume C: [OSDisk] All Key Protectors TPM: ID: {0000000-0000-0000-0000-0000000} Numerical Password: ID: {1000000-1000-1000-1000-1000000} Password: 000000-000000-000000-000000-000000-000000-000000 Data Recovery Agent (Certificate Based): ID: {2000000-2000-2000-2000-2000000} Certificate Thumbprint: 1111111a1aa1a1aa1a1a1a1aaaaaa1aaa1 I would specifically need the line after Numerical Password. 
      Original line:      ID: {1000000-1000-1000-1000-1000000}
      Needed information: -ID: {1000000-1000-1000-1000-1000000}
       
      I apologize in advance for inconveniencing anyone with my silly issues. Hopefully this can stand as a great learning experience for both me and anyone else looking.
       
    • afallenhope
      Rocket League GOOAAL Rando Playback
      By afallenhope
      Hello all! In celebration of Rocket League supporting cross platform play with the XBone I wanted to finally create a script to accompany my game winning goals!
      Currently I have a switch where one button will play this soccer.mp3 while the other cuts the audio in case someone skips the replay during the game. I have a collection of mp3 files that I would like to use from "C:\Rocket" folder and I would like to play a random file from that directory so "C:\Rocket\*.mp3".
       
      I am having trouble understanding the random() function and hot to integrate it. Or would I need to create an array before being able to use the random function? Also for note I am trying to use about 20 mp3 files.
      #include <MsgBoxConstants.au3> Global $g_bPaused = False HotKeySet("{8}", "HotKeyPressed") HotKeySet("{5}", "HotKeyPressed") Func HotKeyPressed() Switch @HotKeyPressed Case "{8}" SoundPlay("") Case "{5}" SoundPlay("C:\Rocket\Soccer.mp3") EndSwitch EndFunc The recordings are newscasters similar to this. Thought that it would have been nice for this to have been in the game to begin with lol Thanks Everyone!
       
       
    • PINTO1927
      view result sql into array
      By PINTO1927
      Hi guys,
      You can run a sql query in a script of autoit ? I would like to see the result in an array table ..
      Thank's
    • Jules
      _FFGetPosition gives error "Array variable has incorrect number of subscripts or subscript dimension range exceeded"
      By Jules
      Hello :),
      I am developing a script with AutoIt for Firefox, to automate performance tests. I have a map, that I have to wait to be loaded, and then I have to click at the center of this map.
      In order to do this, I get the position of the HTML element representing the map, then I perform a few calculations to find center coordinates. But I have a problem.
      I use the FF.au3 library, and the function _FFGetPosition to get the coordinates. My function call is
      $CoordCarte = _FFGetPosition(".getElementById('OpenLayers.Layer.Annotation_3_svgRoot')") and AutoIt gives me this error :
      "C:\Program Files\AutoIt3\Include\FF.au3" (1928) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: Local $aRet[6] = [$aElement[0], $aElement[1], $aContent[0], $aContent[1], $aContent[2], $aContent[3]] Local $aRet[6] = [$aElement[0], ^ ERROR I checked the HTML id of the element, and it is correct (I checked in Firefox with Javascript console).
      I really can't figure out what is my mistake. Could you help me please ?
       
      If this can help you, here is my script (comments are in French) :
      ; ########## ; INCLUSIONS ; ########## #include <Array.au3> #include <FF.au3> #include <String.au3> ; ################## ; PARAMETRES GLOBAUX ; ################## Opt("SendKeyDownDelay",80) ; pas trop rapide pour éviter que des frappes soient perdues Opt("WinTitleMatchMode", 3) ; Noms des fenêtres correspondant exactement Opt("GUIEventOptions", 1) ; ################################################ ; ######## FONCTIONS POUR TESTS DE PERF. ######### ; ################################################ Func FaireUnTest() ; Faire un test de performance pour ArcMap ; ; Return : ; Une chaine de caractères avec les temps de chaque tâche, séparés par des point-virgules Local $LigneTemps = "" ; Contient le temps de chaque tâche, séparés par des point-virgules ; Démarrer Firefox _FFStart() ; Handle de la fenêtre Firefox ouverte $hFirefox = _FFWindowGetHandle() ; Connexion MozRepl _FFConnect() ; ########################### ; ########################### ; ######### TACHE 1 ######### ; ########################### ; ########################### ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Connexion au site de Carmen ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Initialisation nouveau timer $hTimer = TimerInit() ; Aller à l'URL de Carmen et attendre son chargement _FFOpenURL("http://carmen.carmencarto.fr/179/OSUR.map#") ; Attendre le chargement de la carte AttendreChargementCarte() ; Ajout temps de la tâche $LigneTemps = $LigneTemps & ";" & TimerDiff($hTimer) / 1000 ; ########################### ; ########################### ; ######### TACHE 2 ######### ; ########################### ; ########################### ;;;;;;;;;;;;;;;;;;;;; ; Localiser 'ACHUN' ; ;;;;;;;;;;;;;;;;;;;;; ; Initialisation nouveau timer $hTimer = TimerInit() ; L'échelle avant le zoom $queryEchelle = ".getElementsByClassName('DescartesGraphicScale')[1].textContent" $EchelleAvantZoom = _FFCmd($queryEchelle) ; On écrit 'ACHUN' dans le champ de commune $InputCommune = _FFObjGet("combo2", "id") _FFObj($InputCommune, "value", "ACHUN") ; Il faut ensuite sélectionner l'élément 'ACHUN' dans la liste déroulante ControlSend($hFirefox, "", "", _StringRepeat("{TAB}", 27)) ; focus sur liste déroulante 'Commune' ControlSend($hFirefox, "", "", _StringRepeat("{DOWN}", 7)) ; sélection élément 'ACHUN' ControlSend($hFirefox, "", "", "{ENTER}") ; validation ; Clic bouton 'Localiser' _FFClick("button", "tag", 0) ; Attendre que le zoom soit fait (ie un changement d'échelle) While _FFCmd($queryEchelle) = $EchelleAvantZoom WEnd ; Attendre le chargement de la carte AttendreChargementCarte() ; Ajout temps de la tâche $LigneTemps = $LigneTemps & ";" & TimerDiff($hTimer) / 1000 ; ########################### ; ########################### ; ######### TACHE 3 ######### ; ########################### ; ########################### ;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Sélection d'une station ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;########## NE COMPTE PAS DANS LES MESURES ########## ; Inputs 'x' et 'y' de la page web $InputX = _FFObjGet("x", "id") $InputY = _FFObjGet("y", "id") ; Saisie de la position géographique (dans la carte) de la station '04023310' _FFObj($InputX, "value", "747562") _FFObj($InputY, "value", "6667893") ; Centrage de la carte sur la station '04023310' ControlSend($hFirefox, "", "", _StringRepeat("{TAB}", 7)) ; focus sur bouton 'Centrer' ControlSend($hFirefox, "", "", "{ENTER}") ; validation ; On attend le chargement AttendreChargementCarte() ;########## LA SUITE COMPTE MAINTENANT POUR LES MESURES ########## ; Initialisation nouveau timer $hTimer = TimerInit() ; Clic bouton "Interroger les couches" (après navigation avec {TAB} car cela aurait ouvert une fenêtre non voulue) _FFClick("button", "tag", 9) ;$x = _FFObjGet("OpenLayers.Layer.Annotation_3_svgRoot", "id") ;MsgBox(0, $x, $x) ; Coordonnées de la carte, relativement à l'écran d'ordinateur $CoordCarte = _FFGetPosition(".getElementById('OpenLayers.Layer.Annotation_3_svgRoot')") ; Coordonnées coin supérieur gauche $XDebCarte = $CoordCarte[2] $YDebCarte = $CoordCarte[3] MsgBox(0, "$XDebCarte = ", $XDebCarte) MsgBox(0, "$YDebCarte = ", $YDebCarte) ; Coordonnées coin inférieur droit $XFinCarte = $XDebCarte + $CoordCarte[4] $YFinCarte = $YDebCarte + $CoordCarte[5] MsgBox(0, "$XFinCarte = ", $XDebCarte) MsgBox(0, "$YFinCarte = ", $YDebCarte) ; Coordonnées du centre de la carte, relativement à l'écran d'ordinateur $XMilieuCarte = ($XDebCarte + $XFinCarte) / 2 $YMilieuCarte = ($YDebCarte + $YFinCarte) / 2 MsgBox(0, "$XMilieuCarte = ", $XDebCarte) MsgBox(0, "$YMilieuCarte = ", $YDebCarte) ; Cliquer au milieu de la carte MouseClick("left", $XMilieuCarte, $YMilieuCarte, 1, 1) EndFunc FaireUnTest() Func AttendreChargementCarte() ; Met le script en pause jusqu'au chargement complet ; de la carte de l'application Carmen ; Code JavaScript pour récupérer les images de la carte $imagesQuery = ".getElementsByClassName('olTileImage')" ; Le nombre d'images de la carte $NbImages = _FFCmd($imagesQuery & ".length") ; On attend que toutes les images de la carte soit chargées For $i = 0 To $NbImages - 1 ; Le code JavaScript pour savoir si la i-ème image est chargée $imageCompleteQuery = $imagesQuery & "[" & $i & "].complete" ; Et on attend qu'elle soit chargée While Not _FFCmd($imageCompleteQuery) WEnd Next EndFunc