krpandrei Posted February 9, 2010 Share Posted February 9, 2010 I made this script to search for all open/visible windows with title which contains string ATHENA and put them into an array and after that arrange those windows side by side. My problem is that I also whant at the end to delete the arrays completely.I have searched the forum , tried examples but I didn't managed to empty/delete the arrays. expandcollapse popup#include <Array.au3> Global $GUIVersion = "0.0" Global $GUITitle = "Athena Windows Rearrange v" & $GUIVersion Global $HandlesArray[1] Global $TitlesArray[1] $W=@DesktopWidth/2 $H=@DesktopHeight-25 Local $Paused HotKeySet("{PAUSE}", "_TogglePause") HotKeySet("{ESC}", "_Terminate") #Region ### START Koda GUI section ### Form=g:\script\positons final\gui.kxf ;~ $GUI = GUICreate($GUITitle, 400, 400, -1, -1) ;~ GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### _CreateArrays() $rows = UBound($TitlesArray)-1 If $rows = 0 Then $msgtext = "Could not find any open ATHENA projects" & @CRLF & "Please open some for me !" MsgBox ( 0, "Error", $msgtext) ElseIf $rows = 1 Then MsgBox(0, "Error", "I found just one ATHENA window" & @CRLF & "Nothing to do !") Else _RearangeWindows() ;_Delete ($TitlesArray) ;_Delete ($HandlesArray) EndIf Func _CreateArrays() $var = WinList() For $i = 1 to $var[0][0] ; Only display visble windows that have a title If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then $nOffset = 1 ;Option 1, using offset $asResult=StringRegExp($var[$i][0], "ATHENA", 1, $nOffset) ; Search windows titles that contains "ATHENA" sting If @error = 0 Then _ArrayAdd($HandlesArray, $var[$i][1]) ; array with only "Athena" -handels- _ArrayAdd($TitlesArray, $var[$i][0]) ; array with only "Athena" -title names- ;Else ;ExitLoop EndIf EndIf Next ;~ _ArrayDisplay($HandlesArray, "Array: ATHENA handles") ;~ _ArrayDisplay($TitlesArray, "Array: ATHENA titles") EndFunc ;==> Create arrays for existing Athena windows Func IsVisible($handle) If BitAnd( WinGetState($handle), 2 ) Then Return 1 Else Return 0 EndIf EndFunc ;==> Checkes window state is visible Func _RearangeWindows() $WindowsNumber = UBound($TitlesArray)-1 ;total windows number in Titels Array For $i=1 to $WindowsNumber If Mod($i, 2) <> 0 Then ;check if a number is even or not WinMove ($HandlesArray[$i], "",0 ,0 , $W, $H) Else WinMove ($HandlesArray[$i], "", @DesktopWidth/2, 0, $W, $H) EndIf Next EndFunc ;==> Arange windows side by side Func _TogglePause () $Paused = NOT $Paused While $Paused sleep(100) ToolTip($GUITitle & ' is "Paused"',@DesktopHeight/2,@DesktopWidth/2, "", 0, 2) WEnd ToolTip("") EndFunc ;==> TogglePause Func _Terminate () MsgBox(0, $GUITitle, "Exit!") Exit 0 EndFunc ;==> Terminate This is what I tried _Delete ($TitlesArray) _Delete ($HandlesArray) Func _Delete ($aArray) For $i = 1 To Ubound($aArray)-1 _ArrayDelete($aArray, 0) ; Always the first element until $aArray = "" or nothing. Next ;_ArrayDisplay($aArray, "Array after delete") EndFunc Link to comment Share on other sites More sharing options...
NerdFencer Posted February 9, 2010 Share Posted February 9, 2010 (edited) Func _Delete (ByRef $aArray) ; needs byref or you are manipulating a copy ReDim $aArray[1] $aArray[0]=Chr(0) ; NULL EndFunc Edit: typo Edited February 9, 2010 by NerdFencer _________[u]UDFs[/u]_________-Mouse UDF-Math UDF-Misc Constants-Uninstaller Shell Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 9, 2010 Moderators Share Posted February 9, 2010 krpandrei,It is even easier than NerdFencer thinks! From the Help file:"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 = 0This will free the array and convert it back to the single value of 0"No need for ReDim or assigning a valuesto an element.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now