AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Loop, 5 { gui... } only does gui once, then hangs

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
williamsharkey



Joined: 06 Oct 2007
Posts: 52
Location: Philadelphia

PostPosted: Fri Feb 01, 2008 6:49 pm    Post subject: Loop, 5 { gui... } only does gui once, then hangs Reply with quote

Hello,

I am having difficulty using loops with gui's .



So far, it only displays the first gui, and then hangs. I am using the "x" button to close the guis.

Code:
Loop, 5
{
        Gui, Add, Text,cRed , %a_index%
        Gui, Show,, Ahk Rocks
        return
       
        GuiClose:
        GuiEscape:
        Gui, Submit 
        ;gui, destroy
        return
}
Back to top
View user's profile Send private message Visit poster's website
ahklerner



Joined: 26 Jun 2006
Posts: 1219
Location: USA

PostPosted: Fri Feb 01, 2008 7:25 pm    Post subject: Reply with quote

Try this out:
Code:
WasClosed = 1
NumberOfTimes = 5
Loop {
   If (Count = NumberOfTimes) && WasClosed
      Break
   If WasClosed {
      WasClosed = 0
      Count++
      Gui, Add, Text,cRed , %Count%
      Gui, Show,, Ahk Rocks
      }
   Sleep, 500
   }

MsgBox, All %NumberOfTimes% Gui's have been shown and closed
return


GuiClose:
   Gui, Destroy
   WasClosed = 1
Return

Esc::ExitApp

_________________
Back to top
View user's profile Send private message
Firewolf91



Joined: 19 Oct 2007
Posts: 127
Location: PA

PostPosted: Fri Feb 01, 2008 7:38 pm    Post subject: Reply with quote

Not quite sure what you're looking to make this do, but this works just by clicking the Left mouse button.

Code:
Loop, 5
{
Gui, Add, Text, w100 h20, %A_Index%
Gui, Show, w140 h50, Ahk Rocks

KeyWait, LButton, D
Gui, Submit
Gui Destroy
Sleep 200
}

ExitApp


your loop was getting blocked by the "return" in the main GUI. it doesn't have anything to return to.

you can also use this: (i used your code and just added a pause and goto to bypass the return issue...note the order of code matters here!)


Code:
Loop, 5
{
Gui, Add, Text,cRed , %a_index%
Gui, Show, w140 h40, Ahk Rocks
Sleep 200
Pause, On

GuiClose:
GuiEscape:
Gui, Submit
Gui Destroy
goto, PauseTog
return

PauseTog:
Pause, Off
continue
}

ExitApp


you need to use Gui Destroy because otherwise, it'll add to the GUI instead of replacing the number...and it will quickly be adding numbers off the size of the GUI.

EDIT: you could also just remove the width and height from the Gui, Show. that works too. I would still keep Gui Destroy in there tho.
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2592
Location: Australia, Qld

PostPosted: Sat Feb 02, 2008 2:52 am    Post subject: Reply with quote

Why are the GUI subroutines inside the loop? It is not logical...
Code:
Loop, 5
{
    Gui, Add, Text, cRed, %a_index%
    Gui, Show,, Ahk Rocks
    WinWaitClose, Ahk Rocks
    Gui, Destroy

}
return

GuiClose:
GuiEscape:
    Gui, Submit
    ;gui, destroy
return

If you don't need Escape to close the GUI, you can remove the subroutines altogether:
Code:
Loop, 5
{
    Gui, Add, Text, cRed, %a_index%
    Gui, Show,, Ahk Rocks
    WinWaitClose, Ahk Rocks
    Gui, Submit  ; not actually necessary in this case (nothing to submit)
    Gui, Destroy
}
return

Quote:
your loop was getting blocked by the "return" in the main GUI. it doesn't have anything to return to.
More accurately, return exits the loop, either by returning to the caller, or exiting the thread.
the manual wrote:
If there is no caller to which to return, Return will do an Exit instead.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group