Jump to content
Sign in to follow this  
frankpintosr

Time Script where bar shows progress

Recommended Posts

frankpintosr

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

Share this post


Link to post
Share on other sites
ProgAndy

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

Share this post


Link to post
Share on other sites
Valuater

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

Share this post


Link to post
Share on other sites
frankpintosr

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

DUH!!! Thanks that is what I missed!!

Share this post


Link to post
Share on other sites
mentosan

Hi there !

I want to use your script at the beginning of my script but it will exit as soon as the time is up.

Can you help me ?

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.