Jump to content

Time Script where bar shows progress


Recommended Posts

Hello All,

I have a script that someone made and possted here, and I editied a bit for my needs. It was a countdown to restart, but I just need a window with progress bar that acuratly moves along with a countdown timer displayed too. Once time is up, the program exits. It is working fine except, the progress bar is not updating, what am I missing here? Thanks!!

#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <Timers.au3>
#include <Date.au3>
#include <ProgressConstants.au3>

Global $iCountdown = 5; Sets the time-out in seconds

$iTotal_Time = 0
$Prompt = 0

$Form1 = GUICreate("Reminaing Time To Continue", 415, 145, -1, -1, BitOR($WS_CAPTION, $WS_POPUP, $WS_BORDER, $WS_CLIPSIBLINGS), $WS_EX_WINDOWEDGE); Creates GUI Window
$Progress = GUICtrlCreateProgress(10, 65, 395, 15, $PBS_SMOOTH); Creates Progress Bar
GUICtrlSetColor($Progress, 0xff0000); Sets Progress Bar Color
$Label1 = GUICtrlCreateLabel("", 10, 10, 405, 25)
GUISetState(@SW_SHOW)

_Timer_SetTimer($Form1, 1000, '_Countdown')
While 1
    $nMsg = GUIGetMsg()
WEnd

;-------------Functions Below this Line---------------------------

Func _Countdown($hWnd, $iMsg, $iIDTimer, $dwTime)
    $iCountdown -= 1
    $percent_value = Floor(($iCountdown / $iTotal_Time) * 100)
    $percent_value = 100 - $percent_value
    If $iCountdown > 0 Then
        GUICtrlSetData($Label1, $Prompt & _SecsToTime($iCountdown) & " Time Remaining to Continue")
        GUICtrlSetData($Progress, $percent_value)
    ElseIf $iCountdown = 0 Then
        GUICtrlSetData($Label1, $Prompt & _SecsToTime($iCountdown) & " Time Remaining to Continue")
        GUICtrlSetData($Progress, $percent_value)
        Exit
    EndIf
EndFunc ;==>_Countdown

Func _SecsToTime($iSecs)
    Local $iHours, $iMins, $iSec_s
    _TicksToTime($iSecs*1000,$iHours,$iMins,$iSec_s)
    Return StringFormat("%01i:%02i",$iMins, $iSec_s)
EndFunc
Link to comment
Share on other sites

You never set $iTotal_Time to the total time ^_^ I think, in the beginning, it should be the same as the Counter.

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Working...

#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <Timers.au3>
#include <Date.au3>
#include <ProgressConstants.au3>

Global $iCountdown = 6; Sets the time-out in seconds

$iTotal_Time = 5
$Prompt = 0

$Form1 = GUICreate("Reminaing Time To Continue", 415, 145, -1, -1, BitOR($WS_CAPTION, $WS_POPUP, $WS_BORDER, $WS_CLIPSIBLINGS), $WS_EX_WINDOWEDGE); Creates GUI Window
$Progress = GUICtrlCreateProgress(10, 65, 395, 15, $PBS_SMOOTH); Creates Progress Bar
GUICtrlSetColor($Progress, 0xff0000); Sets Progress Bar Color
$Label1 = GUICtrlCreateLabel("", 10, 10, 405, 25)
GUISetState(@SW_SHOW)

_Timer_SetTimer($Form1, 1000, '_Countdown')
While 1
    $nMsg = GUIGetMsg()
WEnd

;-------------Functions Below this Line---------------------------

Func _Countdown($hWnd, $iMsg, $iIDTimer, $dwTime)
    $iCountdown -= 1
    $percent_value = (($iCountdown / $iTotal_Time) * 100)
    If $iCountdown > 0 Then
        GUICtrlSetData($Label1, $Prompt & _SecsToTime($iCountdown) & " Time Remaining to Continue")
        GUICtrlSetData($Progress, $percent_value)
    ElseIf $percent_value <= 0 Then
        GUICtrlSetData($Label1, $Prompt & _SecsToTime($iCountdown) & " Time Remaining to Continue")
        GUICtrlSetData($Progress, $percent_value)
        Exit
    EndIf
EndFunc ;==>_Countdown

Func _SecsToTime($iSecs)
    Local $iHours, $iMins, $iSec_s
    _TicksToTime($iSecs*1000,$iHours,$iMins,$iSec_s)
    Return StringFormat("%01i:%02i",$iMins, $iSec_s)
EndFunc

8)

NEWHeader1.png

Link to comment
Share on other sites

  • 2 weeks later...

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...