Jump to content

[Solved] Stop Array Loop when reachs empty values


 Share

Recommended Posts

Heya

I have made this script, it detects when the mouse is < 3 and minimizes the current active program. It adds the program hande to the array, creates a GUI and sets that to active.

If the mouse is < 3 again and the GUI is still active, it restores all programs in the array and deletes the GUI but if a different program is active, it minimzes that program, adds it to the list and re-actives the GUI

My question is how do i make the

for $ArrayNumber = 1 to 25
    WinSetState($avArray[$ArrayNumber], "", @SW_RESTORE)
    $avArray[$ArrayNumber] = ""
    Next

Only does Next until the array is empty, so it doesn't run all the way to the end. Reason i ask when it does run all the way to the end, it hangs the code until its finished when its only trying to "restore" empty array values

#Include <Misc.au3>
#include <Constants.au3>
#include <WinAPI.au3>

local $LastActiveStored = 0
Local $avArray[26]
local $ArrayNumber
  
    while 1
     sleep(250)
  
  
$pos = MouseGetPos()  
if $pos[1] < 1 then

   if WinActive($LastActiveStored) then
    GUIDelete($Active)
    for $ArrayNumber = 1 to 25
    WinSetState($avArray[$ArrayNumber], "", @SW_RESTORE)
    $avArray[$ArrayNumber] = ""
    Next
    $LastActiveStored = 0
    $ArrayNumber = 0
  
   Else
    $LastActiveStored = WinGetHandle("[Active]")
  
    WinSetState($LastActiveStored, "", @SW_MINIMIZE)
    $ArrayNumber = $ArrayNumber + 1
    $avArray[$ArrayNumber] = $LastActiveStored
  
                If WinExists($Active) Then
                Else                
                $Active = GUICreate('', 0, 0)
                _WinAPI_SetWindowLong(WinGetHandle($Active), $GWL_Exstyle, 0x08000000)
                EndIf
                WinActivate($Active)
                $LastActiveStored = WinGetHandle($Active)
   EndIf
  EndIf
WEnd

Is the full Code

Edited by IanN1990
Link to comment
Share on other sites

This code is doing strange things. Also running a syntax check in SciTE gives warnings, so you need to investigate that. Regarding the loop: if you have an empty array element then do nothing. I don't know if that answers your question or not.

for $ArrayNumber = 1 to 25
    If StringLen($avArray[$ArrayNumber]) Then
        WinSetState($avArray[$ArrayNumber], "", @SW_RESTORE)
        $avArray[$ArrayNumber] = ""
    EndIf
Next
Link to comment
Share on other sites

Aye the script is far from perfect atm :) when ever i am adding new stuff to my main program. I put it into a seperate .au3 so i know the main isn't affecting it.

the problem i was running into was the array was restoring 1, restoring 2, and then trying to restore 3-25 of emptys each time hanging the script which added up to lots of delay ;)

thanks for the code that makes it not run when the array is empty ;)

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