Jump to content

Problem with loop


ttleser
 Share

Recommended Posts

Ok, maybe you guys can help me out, I'm just missing something (maybe I'm tired).

Got a script that windows scheduler will open and run at a certain time. The script is just a reminder script that will flash text and play an audio file every 10secs until the window is closed. Problem with my script is I can't close the window!!! I've got everything else working. :)

Help?

#include <GuiConstants.au3>
#include <Sound.au3>

GUICreate("Reminder",200,100)
$text = GUICtrlCreateLabel("",10,5,180,50)
$exit = GUICtrlCreateButton("Exit", 75, 75, 50, 23)

$sound = _SoundOpen("Reminder.wav", "Startup")

GUISetState ()

while 1
    $msg = GUIGetMsg()

    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $exit
            Exit
    EndSelect

    If $msg <> $GUI_EVENT_CLOSE Or $exit Then
        play()
        Sleep(1000)
        Flash_text()
    Else
        Exit
    EndIf

wend

Func play()
    _SoundPlay($sound, 0)
EndFunc

Func Flash_text()
    GUICtrlSetData ($text," text here")
    sleep(2000)
    GUICtrlSetData ($text,"")
    sleep(1000)
    GUICtrlSetData ($text," text here")
    sleep(2000)
    GUICtrlSetData ($text,"")
    sleep(1000)
EndFunc
Edited by ttleser
Link to comment
Share on other sites

It looks like your program is in the loop most of the time when you are hitting the exit or gui close. I took your code and converted to OnEvent mode which seems to solve the problem.

#include <GuiConstants.au3>
#include <Sound.au3>

Opt("GUIOnEventMode", 1) 

GUICreate("Reminder",200,100)
$text = GUICtrlCreateLabel("",10,5,180,50)
$exit = GUICtrlCreateButton("Exit", 75, 75, 50, 23)
$sound = _SoundOpen("Reminder.wav", "Startup")

GUISetState ()

GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
GUICtrlSetOnEvent($exit, "_Quit")

While 1
    sleep(1000)
        play()
        Sleep(100)
        Flash_text()
WEnd

Func _Quit()
    Exit
EndFunc

Func play()
    _SoundPlay($sound, 0)
EndFunc

Func Flash_text()
    GUICtrlSetData ($text," text here")
    sleep(2000)
    GUICtrlSetData ($text,"")
    sleep(1000)
    GUICtrlSetData ($text," text here")
    sleep(2000)
    GUICtrlSetData ($text,"")
    sleep(1000)
EndFunc
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...