Jump to content
Sign in to follow this  
sublimnl

Gui Events only work once?

Recommended Posts

sublimnl

I am writing a script that will check a file to determine whether or not a user has entered their timesheet and prompt them to do so if they have not. The prompt allows the user to specify choose to be reminded later on if they cannot do their timesheet when they are originally prompted. The problem I am having is that the second time the GUI is presented via the Prompt() function, none of the GuiCtrlSetOnEvent lines work at all. What am I doing wrong?

#include <file.au3>
#include <guiconstants.au3>
#include <ie.au3>

$seed = Random(1,5)
Global $timer = Round(300000 + $seed*60000)
Global $filearray
Global $combo1
Global $Form1
Global $BtnYes
Global $BtnRemind

Opt("GUIOnEventMode",1)

$timer = 0
Wait()

Func Wait()
    While 1
        Sleep($timer)
        _FileReadToArray("C:\bstusers.txt",$filearray)
        For $i = 1 to $filearray[0]
            If StringInStr($filearray[$i],@UserName) > 0 Then
                Prompt()
            EndIf
        Next
    WEnd
EndFunc


Func Prompt()
    $Form1 = GUICreate("Timesheet Reminder", 327, 238, 192, 125)
    GUICtrlCreateLabel("You have not completed your timesheet yet." & @CRLF & "Would you like to do this now?", 8, 8, 547, 71)
    GUICtrlSetFont(-1, 12, 400, 0, "Tahoma")
    $BtnYes = GUICtrlCreateButton("YES", 99, 96, 119, 41)
    $BtnRemind = GUICtrlCreateButton("Remind me in...", 99, 152, 119, 41)
    $Combo1 = GUICtrlCreateCombo("", 99, 208, 121, 21,$CBS_DROPDOWNLIST)
    GUICtrlSetData($combo1,"15 minutes|30 minutes|45 minutes|1 hour|1.5 hours|2 hours","15 minutes")
    GUISetState(@SW_SHOW)
    GUICtrlSetOnEvent($BtnYes,"IEGo")
    GUICtrlSetOnEvent($BtnRemind,"Remind")
    GuiSetOnEvent($GUI_EVENT_CLOSE, "Remind")
    While 1
        Sleep(250)
    WEnd
EndFunc

Func Remind()
    GUISetState(@SW_HIDE,$Form1)
    Select
        Case GUICtrlRead($combo1) = "15 minutes"
            $timer = 5000
        Case GUICtrlRead($combo1) = "30 minutes"
            $timer = 30*60000
        Case GUICtrlRead($combo1) = "45 minutes"
            $timer = 45*60000
        Case GUICtrlRead($combo1) = "1 hour"
            $timer = 60*60000
        Case GUICtrlRead($combo1) = "1.5 hours"
            $timer = 90*60000
        Case GUICtrlRead($combo1) = "2 hours"
            $timer = 120*60000
    EndSelect
    GUIDelete($Form1)
    Wait()
EndFunc

Func IEGo()
    GUISetState(@SW_HIDE,$Form1)
    _IECreate("http://finweb")
    $timer = 60000
    GUIDelete($Form1)
    Wait()
EndFunc

Share this post


Link to post
Share on other sites
Jos

You make a fundamental mistake here..

Wait() is calling prompt() which is calling Remind() which is calling Wait() again and no Func ever "ends" properly.

You have to return from an Event before the next message in the queue is processed. So the Wait() statement in the Prompt Remind function will have to be removed and you have to build logic in the While-wend loop locate in Prompt() to exit that loop when Remind was fired.


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
sublimnl

You make a fundamental mistake here..

Wait() is calling prompt() which is calling Remind() which is calling Wait() again and no Func ever "ends" properly.

You have to return from an Event before the next message in the queue is processed. So the Wait() statement in the Prompt Remind function will have to be removed and you have to build logic in the While-wend loop locate in Prompt() to exit that loop when Remind was fired.

Thanks...I'll give that a shot. Now that I think about it, I am probably guilty of this quite a bit of the time...thanks for pointing that out.

Edit: Got it working! Just tested whether or not the GUI handle was valid in the while loop. Since I GuiDelete in Remind() and IEGo() this works perfect and makes the Prompt() func return properly. Thanks again!

Edited by sublimnl

Share this post


Link to post
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
Sign in to follow this  

×