Jump to content

Exit loop with an event


Recommended Posts

Ok, I did search but didn't find what I was looking for (I'm sorry! Please stop yelling at me!!) :lmao: ... basically I'm setting up a loop (either a do or a while loop) that I need to exit from when $GUI_EVENT_CLOSE occurs. Here's a rough draft:

Func _PingFunction($Server)
    $gPingWindow = GuiCreate(Something, something, something)
    $lvPingTime = GuiCtrlCreateListView(blah,blah,blah)
    GuiSetState(@SW_SHOW,$gPingWindow)

    Do
        $iPing = Ping($Server)
        If $iPing > 0 Then 
            GuiCtrlCreateListViewItem('Ping Time: '&$iPing,$lvPingTime)
        Else
            GuiCtrlCreateListViewItem('Timeout',$lvPingTime)
        Sleep(1000)
    Until @GUI_CtrlID = $GUI_EVENT_CLOSE
EndFunc

There is more to the function but I can't exit the loop. Any other opened windows have been disabled and can't receive input. I could work around it using AdlibEnable and call the function every second, but I'd really like to know if using a loop is feasible.

OnEvent is properly enabled and all my controls are working up to this point.

Link to comment
Share on other sites

Maybe

Func _PingFunction($Server)
    $gPingWindow = GuiCreate(Something, something, something)
    $lvPingTime = GuiCtrlCreateListView(blah,blah,blah)
    GuiSetState(@SW_SHOW,$gPingWindow)

    Do
        $iPing = Ping($Server)
        If $iPing > 0 Then 
            GuiCtrlCreateListViewItem('Ping Time: '&$iPing,$lvPingTime)
ExitLoop
        Else
            GuiCtrlCreateListViewItem('Timeout',$lvPingTime)
        Sleep(1000)
    Until @GUI_CtrlID = $GUI_EVENT_CLOSE
EndFunc

8)

NEWHeader1.png

Link to comment
Share on other sites

Maybe

Func _PingFunction($Server)
    $gPingWindow = GuiCreate(Something, something, something)
    $lvPingTime = GuiCtrlCreateListView(blah,blah,blah)
    GuiSetState(@SW_SHOW,$gPingWindow)

    Do
        $iPing = Ping($Server)
        If $iPing > 0 Then 
            GuiCtrlCreateListViewItem('Ping Time: '&$iPing,$lvPingTime)
ExitLoop
        Else
            GuiCtrlCreateListViewItem('Timeout',$lvPingTime)
        Sleep(1000)
    Until @GUI_CtrlID = $GUI_EVENT_CLOSE
EndFunc

8)

Wouldn't that just exit the loop after the first successful ping? The script needs to ping the server until the window is closed. Edited by cjconstantine
Link to comment
Share on other sites

Missing an EndIf for 'If $iPing > 0 Then'

Not saying that's the problem. Just saying you're missing it. :ph34r:

Oops .... minor slip up, I was just retype part of the code from memory :">

Oh, and I know the (something, something, something) and (blah, blah, blah) won't work either :lmao:

Edited by cjconstantine
Link to comment
Share on other sites

Why not don't use OnEvent, then replace this:

Until @GUI_CtrlID = $GUI_EVENT_CLOSEoÝ÷ Û­Øb±«­¢+ØU¹Ñ¥°U%Ñ5Í ¤ôÀÌØíU%}Y9Q}
1=M

#)

Link to comment
Share on other sites

I would recommend pinging a certain number of times rather than infinitely until someone closes the window. I just tried something similar, and unless you create a new window just for the ping I dont see this as feasable.

Edit: Even with a new window I dont see this as feasable.

JS

Edited by JSThePatriot

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Why not don't use OnEvent, then replace this:

Until @GUI_CtrlID = $GUI_EVENT

#)

Not use OnEvent ... that would be a lot of code to replace. :lmao:

To JSThePatriot:

It does open a new window, typically the program only pings a server every 5 minutes (which can be adjusted if needed). But this will only be used to know if/when a server comes back online after a reboot.

I've already written the code using an Adlib function so no loop is required, it just would have been nice :ph34r:

Edited by cjconstantine
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...