Jump to content
Sign in to follow this  
PcExpert

Increase progressbar every X seconds with 1%

Recommended Posts

PcExpert

Hi all,

How can I make a progressbar that does the following: I specify the amount of seconds in the script, the program will split it in 100 ( / 100) and then the progressbar will increase every X seconds 1%. I hope my explanation will be good. :)

I tried this, but didnt have the result I wanted:

#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>

Global $proc_cur = "0" , $sec2

$sec = "12"
If $sec < "100"Then
$sec2 = "000"
Else
$sec2 = "00"
EndIf

$calc_sec = $sec / 100
$days = StringSplit($calc_sec, ".")

;MsgBox(0, "", $days[1] & $days[2] & "00")

GUICreate("My GUI Progressbar", 220, 100, 100, 200)
 $progressbar1 = GUICtrlCreateProgress(10, 10, 200, 20)
 GUISetState()

 While 1
  $msg = GUIGetMsg()
  Sleep($days[1] & $days[2] & $sec2)
  $proc_cur =  $proc_cur + 1
  GUICtrlSetData($progressbar1, $proc_cur) 
  If $msg = $GUI_EVENT_CLOSE Then ExitLoop
 WEnd

Share this post


Link to post
Share on other sites
sandin

#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>

$time = InputBox("time", "input percentage interval increasement in seconds", 1) ; sec
if @error then Exit
$time1 = $time*1000

GUICreate("My GUI Progressbar", 220, 100, 100, 200)
$progressbar1 = GUICtrlCreateProgress(10, 10, 200, 20)
GUISetState()
$timer = TimerInit()

 While 1
    if GUIGetMsg() = $GUI_EVENT_CLOSE then Exit
    $progress_data = GUICtrlRead($progressbar1)
    if $progress_data = 100 Then
        MsgBox(0, "100%", "your progress has reached 100%", 15)
        Exit
    EndIf
    if TimerDiff($timer) >= $time1 Then
        GUICtrlSetData($progressbar1, $progress_data+1)
        $timer = TimerInit()
    EndIf
 WEnd

Share this post


Link to post
Share on other sites
PcExpert

Thanks for the code sandin, but this does exactly the same as my code. For example: Lets say 200 seconds, so the progress bar would increment 0,5% every 1 second. Thats what I want to do. Hope this helps :)

Edited by PcExpert

Share this post


Link to post
Share on other sites
goldenix

have you looked into the Help file example of GUICtrlCreateProgress ?

Edited by goldenix

My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]

Share this post


Link to post
Share on other sites
PcExpert

yes, and also progresson() , but I cant figure out how to get it to work the way I want it to.

Share this post


Link to post
Share on other sites
sandin

or this:

#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>

$time = InputBox("time", "input full time in seconds", 15) ; sec
if @error then Exit
$time1 = $time*1000

GUICreate("My GUI Progressbar", 220, 100, 100, 200)
$progressbar1 = GUICtrlCreateProgress(10, 10, 200, 20)
GUISetState()
$timer = TimerInit()

 While 1
    if GUIGetMsg() = $GUI_EVENT_CLOSE then Exit
    $progress_data = GUICtrlRead($progressbar1)
    if $progress_data = 100 Then
        MsgBox(0, "100%", "your progress has reached 100%", 15)
        Exit
    EndIf
    $Percentage_data = TimerDiff($timer)*100/$time1
    GUICtrlSetData($progressbar1, $Percentage_data)
 WEnd

Share this post


Link to post
Share on other sites
PcExpert

Thats it! Thank you!

Share this post


Link to post
Share on other sites
JesseBarnett

In Scite, open up Autoit help and do a search for the phrase "timer". Click on the Function_Timer_SetTimer entry.

Should be what you are looking for. The example script does a progress bar with different time settings.

EDIT: Well hell! I must be getting old......................... In the time it took me to type a reply there have been umpteem jillion replies and a resolution.

Edited by JesseBarnett

Share this post


Link to post
Share on other sites
PcExpert

I tried to implement it to my script, so it became this:

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_Description=Internet Payment System
#AutoIt3Wrapper_Res_Fileversion=1.4
#AutoIt3Wrapper_Res_LegalCopyright=Me
#AutoIt3Wrapper_Res_Language=1043
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
; Script Start - Add your code below here


$gui_time = GUICreate("Internet Café 1.4", @DesktopWidth, 35, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW & $WS_EX_TOPMOST)  ; will create a dialog box that when displayed is centered
$label_time = GUICtrlCreateLabel("0:00", 0, 0, 80, 50)
GUICtrlSetFont(-1, 24)
$btn_signout = GUICtrlCreateButton("Uitloggen", 90, 0, 60, 35)
$progressbar1 = GUICtrlCreateProgress(160, 0, @DesktopWidth -200, 35)
GUISetState(@SW_SHOW, $gui_time)       ; will display an empty dialog box


$time_base_read = 10 ; the amount of seconds
$time1 = $time_base_read*1000
$time = TimerInit()
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
  Case $btn_signout
   logout() 
    EndSwitch
    $new = (1 * $time_base_read * 1000) - TimerDiff($time)
    $seconds = Round($new / 1000)
    $newMin = Floor($seconds / 60)
    $newSec = Mod($seconds, 60)
    If $newSec < 10 Then $newSec = "0" & $newSec
    If ($newMin > 0 Or Number($newSec) > 0) Then 
        GUICtrlSetData($label_time, $newMin & ":" & $newSec)
 $progress_data = GUICtrlRead($progressbar1)
   ; if $progress_data = 100 Then
    ;    Exit
    ;EndIf
    $Percentage_data = TimerDiff($time)*100/$time1
    GUICtrlSetData($progressbar1, $Percentage_data) 
    Else
        GUICtrlSetData($label_time, "0:00")
  Sleep(3000)
  Exit
    EndIf
WEnd

Func logout()
Exit
EndFunc

But when I run this, and the timer reaches 0:00 the progressbar isnt full yet. Any way to solve this, so that the progressbar is full when the timer reaches 0:00? thanks!

Edited by PcExpert

Share this post


Link to post
Share on other sites
sandin

#include <GUIConstants.au3>
#include <WindowsConstants.au3>

$gui_time = GUICreate("Internet Café 1.4", @DesktopWidth, 35, 0, 0, $WS_POPUP, $WS_EX_TOOLWINDOW & $WS_EX_TOPMOST)  ; will create a dialog box that when displayed is centered
$label_time = GUICtrlCreateLabel("0:00", 0, 0, 80, 50)
GUICtrlSetFont(-1, 24)
$btn_signout = GUICtrlCreateButton("Uitloggen", 90, 0, 60, 35)
$progressbar1 = GUICtrlCreateProgress(160, 0, @DesktopWidth -200, 35)
GUISetState(@SW_SHOW, $gui_time)       ; will display an empty dialog box


$time_base_read = 5 ; the amount of seconds
$time1 = $time_base_read*1000
$minutes = Floor($time1/60)
$seconds = $time1-$minutes*60
GUICtrlSetData($label_time, $minutes & ":" & $seconds)

$time = TimerInit()

Global $old_data

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $btn_signout
        logout()
    EndSwitch
    $min1 = Floor((($time1+1000-TimerDiff($time))/60000))
    if StringLen($min1) = 1 then $min1 = "0" & $min1
    $minutes = $min1
    $sec1 = Floor(($time1+1000-TimerDiff($time)-($min1*60000))/1000)
    if StringLen($sec1) = 1 then $sec1 = "0" & $sec1
    $seconds = $sec1
    $Percentage_data = TimerDiff($time)*100/$time1
    GUICtrlSetData($progressbar1, $Percentage_data)
    if $minutes & $seconds <> $old_data Then
        GUICtrlSetData($label_time, $minutes & ":" & $seconds)
        $old_data = $minutes & $seconds
    EndIf
    if GUICtrlRead($progressbar1) = 100 Then
        MsgBox(0, "100%", "100%")
        Exit
    EndIf
    Sleep(10)
WEnd

Func logout()
    Exit
EndFunc

edit: making time count-down smoother (no flashing of numbers)

Edited by sandin

Share this post


Link to post
Share on other sites
PcExpert

Thanks again Sandin!

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  

×