Jump to content

Cant figure out how to make simple progress timer


Recommended Posts

I want to make progress bar which would count seconds. For example progress is for 10min

ProgressOn("Progress Meter", "Increments every second", "0 ")
For $i = 1 to 600 ; i can change whatever number but its same
    sleep(1000)
    ProgressSet( $i, $i & " secs")
Next
ProgressSet(600 , "Done", "Complete")
sleep(500)
ProgressOff()

Its really simple but cant figure out lol.

Edited by Edgaras
Link to comment
Share on other sites

This will give you the percentage that you need for the progress bar increments

ProgressOn("Progress Meter", "Increments every second", "0 ")
For $i = 1 To 120 ; i can change whatever number but its same
     Sleep(1000)
     ProgressSet(($i / 120) * 100, $i & " secs")
Next
ProgressSet(600, "Done", "Complete")
Sleep(500)
ProgressOff()

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

ProgressOn is a predefined GUI with a progress bar, you'd have to make your own GUI and ProgressBar, or you could use the one that's linked in my signature that allows you to create a sizable GUI with progress bar and label.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Thanks. But its also posible to make GUI borderless, titleless ?

Yes it's possible, look at the style and extended style settings for GUICreate. BTW, the UDF in my signature uses the $WS_POPUP and $WS_DLGFRAME styles. The borders are very small and there's no titlebar. Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I just saw I can make it with simple gui.

#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 243, 23, 329, 312)
$Progress1 = GUICtrlCreateProgress(0, 0, 238, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

For $i = 1 To 600 ; i can change whatever number but its same
     Sleep(1000)
     GUICtrlSetData($progress1,$i)
Next

But how to make it for 10mins too? Like ProgressSet(($i / 600) * 100, $i & " secs")

but with guictrlsetdata

Link to comment
Share on other sites

I just saw I can make it with simple gui.

But how to make it for 10mins too? Like ProgressSet(($i / 600) * 100, $i & " secs") but with guictrlsetdata

You need to convert the current time to a percentage of the total time, see the code below, I have included comments to show how to do it.

#region ### START Koda GUI section ### Form=
$TimeToRun = InputBox("Time to run", "Enter the time (in minutes) you want this to run)")
$Form1 = GUICreate("Form1", 243, 23, 329, 312)
$Progress1 = GUICtrlCreateProgress(0, 0, 238, 17)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
$Time = $TimeToRun * 60 ; minutes to run
For $i = 1 To $Time ; $Time = $TimeToRun * 60 seconds
    Sleep(1000)
    ; ($i/$Time) * 100 = current count divided by total time, times 100 gives you percentage of elapsed time
    GUICtrlSetData($Progress1, ($i / $Time) * 100) 
Next

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
HotKeySet("{ESC}", "Start")
#region ### START Koda GUI section ### Form=
$TimeToRun = InputBox("Time to run", "Enter the time (in minutes) you want this to run)")
$Form1 = GUICreate("Form1", 238, 17, 330, 310,$WS_POPUP) ; not sure about $ws_popup. But it works(deletes borders)
$Progress1 = GUICtrlCreateProgress(0, 0, 238, 17)
GUISetState(@SW_SHOW)

#endregion ### END Koda GUI section ###
While 1
sleep(10)
Wend
Func Start()
$Time = $TimeToRun * 60 ; minutes to run
For $i = 1 To $Time ; $Time = $TimeToRun * 60 seconds
    Sleep(1000)
    ;($i/$Time) * 100 = current count divided by total time, times 100 gives you percentage of elapsed time
    GUICtrlSetData($Progress1, ($i / $Time) * 100)
Next
EndFunc

So i also placed hotkey, when you press esc counting starts. Now how I should make this to be always on window? I mean i want to be it always visible.

Edited by Edgaras
Link to comment
Share on other sites

Look at the extended styles for GUICreate, specifically $WS_EX_TOPMOST.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...