Sign in to follow this  
Followers 0
Zamphire

Showing Time in label

5 posts in this topic

So I'm trying to make a simple GUI for a small program I've written. Most everything works but I'm trying to get it to display the time until next run in the GUI.

Now I had someone else here on the forums make it so that the tray tooltip updated with the time until next run and I was trying to use that same code to make this work but I can't seem to get it to work. Here's the code, maybe someone can help.

#include <GUIConstantsEx.au3>
Opt('MustDeclareVars', 1)
Global $lastran = TimerInit()
Global $Timer = TimerInit()
Global $Timer2 = TimerInit()
Global $Delay = 1
Global $Delay2 = 1
Example()
Func Example()
    Local $Button_1, $Button_2, $checkCN, $msg
    GUICreate("BoxStor Auto Checker", 300, 100) ; will create a dialog box that when displayed is centered
    Opt("GUICoordMode", 2)
Time()
    $Button_1 = GUICtrlCreateButton("Check Warehouse", 35, 30, 120)
    $Button_2 = GUICtrlCreateButton("Exit Program", 0, -1)
$checkCN = GUICtrlCreateCheckbox("Auto Check BoxStor", -1, 1, 120, 20)
$NextRunLabel = GUICtrlCreateLabel("Time Until Next Run: " & $Minutes & "min", 50, 30)
    GUISetState()     ; will display an  dialog box with 2 button
    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $Button_1
                CheckBoxStor()    ; Hopefully will run Warehouse
            Case $msg = $Button_2
                DoExit()
   Case $msg = $checkCN
    CheckForBoxstor()
   Case $msg = $NextRunLabel
    DoExit()
        EndSelect
    WEnd
EndFunc   ;==>Example
Func CheckBoxStor()
If WinExists("Warehose Menu Options") Then
  WinActivate("Warehose Menu Options")
        ControlClick("Warehose Menu Options", "", "[CLASS:TBitBtn; INSTANCE:7]")
  WinWaitActive("New Warehouse Orders")
  ControlClick("New Warehouse Orders", "", "[CLASS:TBitBtn; TEXT:&Print All; INSTANCE:1]")
  $lastran = TimerInit()
Else
  MsgBox(0, "", "Please Log Into BoxStor Warehouse then rerun.")
EndIf
EndFunc
Func CheckForBoxstor()
If WinExists("Warehose Menu Options") Then
  AutoCheck()
Else
  GUICtrlSetState ( 5, $GUI_UNCHECKED)
  MsgBox(0, "", "Please Log Into BoxStor Warehouse then rerun.")
EndIf
EndFunc
 
Func AutoCheck()
While 1
    While @HOUR >= 8 And @HOUR < 17 ; easier to code it this way
        If TimerDiff($Timer) >= $Delay Then; Wait 30 minutes before running it again
            WinActivate("Warehose Menu Options")
            ControlClick("Warehose Menu Options", "", "[CLASS:TBitBtn; INSTANCE:7]")
            WinWaitActive("New Warehouse Orders")
            ControlClick("New Warehouse Orders", "", "[CLASS:TBitBtn; TEXT:&Print All; INSTANCE:1]")
            $Timer = TimerInit()
            $Delay = 1800000
        EndIf
        Sleep(100)
        If TimerDiff($Timer2) >= $Delay2 Then ; Only updates the time on the tool tip aprrox. once a minute
            Global $Minutes = 30 - Int(TimerDiff($Timer) / 60000)
            TraySetToolTip("Time Until Next Run: " & $Minutes & "min")
            $Timer2 = TimerInit()
            $Delay2 = 61000
        EndIf
    WEnd
     TraySetToolTip("Script is sleeping until 8AM")
    $Delay = 1
    $Delay2 = 1
    Sleep(100)
WEnd
EndFunc
Func Time()
TimerDiff($Timer2) >= $Delay2 Then ; Only updates the time on the tool tip aprrox. once a minute
Global $Minutes = 30 - Int(TimerDiff($Timer) / 60000)
    TraySetToolTip("Time Until Next Run: " & $Minutes & "min")
    $Timer2 = TimerInit()
    $Delay2 = 61000
EndFunc
Func DoExit()
EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You could simply use the same Function that updates the tooltip to update your label using GuiCtrlSetData()

Func Time()
TimerDiff($Timer2) >= $Delay2 Then ; Only updates the time on the tool tip aprrox. once a minute
Global $Minutes = 30 - Int(TimerDiff($Timer) / 60000)
    TraySetToolTip("Time Until Next Run: " & $Minutes & "min")
    GUICtrlSetData( $NextRunLabel, "Time Until Next Run: " & $Minutes & "min")
    $Timer2 = TimerInit()
    $Delay2 = 61000
EndFunc

Hope this is what you were looking for.

Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

Alright, I added in your suggestion? I don't get any errors, but the label on the GUI isn't updating. Here's my code, any idea how to get it to update? (It updates on the tooltip just fine.)

; ~~~~~~~~~~~~~~Version Info~~~~~~~~~~~~~~
; Version Number: 0.5
; Version Date: 11/29/2011
#include <GUIConstantsEx.au3>
Opt('MustDeclareVars', 1)
Global $lastran = TimerInit()
Global $TimeLeft = 30 - Int(TimerDiff($Lastran) / 60000)
Global $Timer = TimerInit()
Global $Timer2 = TimerInit()
Global $Delay = 1
Global $Delay2 = 1
Global $NextRunLabel = 1
Example()
Func Example()
    Local $Button_1, $Button_2, $checkCN, $NextRunLabel, $msg
    GUICreate("BoxStor Auto Checker", 300, 100) ; will create a dialog box that when displayed is centered
    Opt("GUICoordMode", 1)
    $Button_1 = GUICtrlCreateButton("Check Warehouse", 30, 25, 120)
    $Button_2 = GUICtrlCreateButton("Exit Program", 155, 25, 120)
$checkCN = GUICtrlCreateCheckbox("Auto Check BoxStor", 155, 60, 120, 20)
$NextRunLabel = GUICtrlCreateLabel("Time Until next Run: " & $TimeLeft & "min", 15, 63)
    GUISetState()     ; will display an  dialog box with 2 button
    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $Button_1
                CheckBoxStor()    ; Hopefully will run Warehouse
            Case $msg = $Button_2
                DoExit()
   Case $msg = $checkCN
    CheckForBoxstor()
   Case $msg = $NextRunLabel
    DoExit()
        EndSelect
    WEnd
EndFunc   ;==>Example
Func CheckBoxStor()
If WinExists("Warehose Menu Options") Then
  WinActivate("Warehose Menu Options")
        ControlClick("Warehose Menu Options", "", "[CLASS:TBitBtn; INSTANCE:7]")
  WinWaitActive("New Warehouse Orders")
  ControlClick("New Warehouse Orders", "", "[CLASS:TBitBtn; TEXT:&Print All; INSTANCE:1]")
  $lastran = TimerInit()
Else
  MsgBox(0, "", "Please Log Into BoxStor Warehouse then rerun.")
EndIf
EndFunc
Func CheckForBoxstor()
If WinExists("Warehose Menu Options") Then
  AutoCheck()
Else
  GUICtrlSetState ( 5, $GUI_UNCHECKED)
  MsgBox(0, "", "Please Log Into BoxStor Warehouse then rerun.")
EndIf
EndFunc
 
Func AutoCheck()
While 1
    While @HOUR >= 8 And @HOUR < 17 ; easier to code it this way
        If TimerDiff($Timer) >= $Delay Then; Wait 30 minutes before running it again
            WinActivate("Warehose Menu Options")
            ControlClick("Warehose Menu Options", "", "[CLASS:TBitBtn; INSTANCE:7]")
            WinWaitActive("New Warehouse Orders")
            ControlClick("New Warehouse Orders", "", "[CLASS:TBitBtn; TEXT:&Print All; INSTANCE:1]")
            $Timer = TimerInit()
            $Delay = 1800000
        EndIf
        Sleep(100)
        If TimerDiff($Timer2) >= $Delay2 Then ; Only updates the time on the tool tip aprrox. once a minute
            Global $Minutes = 30 - Int(TimerDiff($Timer) / 60000)
            TraySetToolTip("Time Until Next Run: " & $Minutes & "min")
   GUICtrlSetData( $NextRunLabel, "Time Until Next Run: " & $Minutes & "min")
   $Lastran = $Minutes
            $Timer2 = TimerInit()
            $Delay2 = 61000
        EndIf
    WEnd
     TraySetToolTip("Script is sleeping until 8AM")
    $Delay = 1
    $Delay2 = 1
    Sleep(100)
WEnd
EndFunc
Func DoExit()
Exit
EndFunc

Share this post


Link to post
Share on other sites

Zamphire,

First, attempt to post your code in a clean structure & manner. The way you post your code is hardily readable. Thus I misunderstood how your first example worked, Or I would have suggest another route.

The function GuiCtrlSetData() I suggested should update your Label with the new data every time it is called. However in your new and rewritten script, it is only called when CheckForBoxstor() is called. so It's only going to update when that function is called. What I'd suggest is writing your time function seperately, and calling it from your main loop so that it is checked and called upon constantly for a constant update to the label.


My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

Coded for you, hope you can figure out how to use it.

Opt("GUIOnEventMode", 1)
GUICreate("GUI Countdown Timer", 320, 240)
GUISetOnEvent(-3, "_Exit")
$Button = GUICtrlCreateButton("Start Timer", 10, 10, 150, 30)
GUICtrlSetOnEvent(-1, "_Button")
$Label = GUICtrlCreateLabel("", 10, 50, 150, 20)
GUISetState()
;~ ----------------------------------------------------------------------------------------------------
Func _Exit()
Exit
EndFunc   ;==>_Exit
Func _Button()
_StartTimer(TimerInit(), 10)
EndFunc
Func _StartTimer($Timer, $TotalTime, $i = 0)
If $i = ($TotalTime + 1) Then
  MsgBox(0, '', "Game Over")
  Return
EndIf
If TimerDiff($Timer) > ($i * 1000) Then
  GUICtrlSetData($Label, $i)
  $i += 1
  _StartTimer($Timer, $TotalTime, $i)
Else
  Sleep(100)
  _StartTimer($Timer, $TotalTime, $i)
EndIf
EndFunc   ;==>_StartTimer
;~ ----------------------------------------------------------------------------------------------------
While 1
Sleep(1000)
WEnd

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  
Followers 0