Sign in to follow this  
Followers 0
noobish

2 hours how many seconds in script

10 posts in this topic

Hi guys again in this script is set to popup something every 30 secs as you can see :

$warn_intrvl = 30, $display_time

How to make it pop up every 2 hours ? i put 7200 but nothing happen after 2 hours.

local $target_date = '2013/01/01 00:00:00'
local $hrs, $mins, $secs, $days=0, $diff, $warn = 24*60*60, $warn_intrvl = 30, $display_time

Thank you.

Share this post


Link to post
Share on other sites



Can you post the whole code so we can see what your script does (or doesn't)?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Yes water of course here it is and is made by Kylomas

#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <date.au3>
local $target_date = '2013/01/01 00:00:00'
local $hrs, $mins, $secs, $days=0, $diff, $warn = 24*60*60, $warn_intrvl = 30, $display_time

local $gui010 = guicreate('',@DesktopWidth,20,(@desktopwidth)/2,20,$ws_popup,bitor($ws_ex_layered,$ws_ex_topmost))
GUISetBkColor(0xABCDEF)
local $lbl010 = guictrlcreatelabel('',0,0,600,20)
guictrlsetfont(-1,10,800,-1,'lucinda console')
_WinAPI_SetLayeredWindowAttributes($gui010, 0xABCDEF, 250)
guisetstate()

adlibregister('_update',1000)

while guigetmsg() <> $gui_event_close

wend

func _update()

$diff = _datediff('s',_NowCalc(),$target_date)

; calculations made from UEZ

Local $secs = Mod($diff, 60)
Local $mins = Mod(Int($diff / 60), 60)
Local $hrs = Int($diff / 60 ^ 2)
If $hrs > 23 Then
$days = Floor($hrs/ 24)
$hrs -= $days * 24
endif

local $diff_out = stringformat('%02i Days %02i Hours %02i Minutes %02i Seconds to ' & stringleft($target_date,stringinstr($target_date,' ')), $days, $hrs, $mins, $secs)
guictrlsetdata($lbl010,$diff_out)
$warn -= 1
if mod($warn,$warn_intrvl) = 0 then
traytip('',$warn_intrvl & ' seconds have passed' & @lf & $diff_out,5)
$display_time = 1
endif
if $display_time = 10 then
traytip('','',0)
$display_time = 0
endif
if $display_time then $display_time += 1

endfunc
Edited by noobish

Share this post


Link to post
Share on other sites

noobish,

Where did you change $warn_intrvl?

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Why do you set "$warn -= 1" in your code? It overwrites "$warn = 24*60*60"


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

@Kylomas

I didn't change nothing is the same as you posted

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

@water the $warn -= 1 is correct. It decrements a counter that the modulo arithmetic is dependent upon.

@noobish - I think this is a timing problem. I am running the adlib every second so it might have crossed the 1 second boundry and caused the mod function to never return '0'. Changed the adlib to run every 1/2 second and added some consolewrite messages.

I also expanded the total time interval to one year and and set the warn interval to 2 hours.

If you did NOT change anything then why would you expect it to warn after 2 hours? Regardless, this made me aware of the possible timing issue.

#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <date.au3>

local $target_date  = '2013/01/01 00:00:00'
local $hrs, $mins, $secs, $days=0, $diff, $warn = 365*24*60*60, $warn_intrvl = 2 * 60 * 60, $display_time
ConsoleWrite($warn & ' ' & $warn_intrvl & @LF)

local $gui010   =   guicreate('',@DesktopWidth,20,(@desktopwidth)/2,20,$ws_popup,bitor($ws_ex_layered,$ws_ex_topmost))
                    GUISetBkColor(0xABCDEF)
local $lbl010   =   guictrlcreatelabel('',0,0,600,20)
                    guictrlsetfont(-1,10,800,-1,'lucinda console')
                    _WinAPI_SetLayeredWindowAttributes($gui010, 0xABCDEF, 250)
                    guisetstate()

adlibregister('_update',500)

while guigetmsg() <> $gui_event_close

wend

func _update()

    $diff = _datediff('s',_NowCalc(),$target_date)

    ; calcs from UEZ

    Local $secs = Mod($diff, 60)
    Local $mins = Mod(Int($diff / 60), 60)
    Local $hrs  = Int($diff / 60 ^ 2)
    If $hrs > 23 Then
        $days = Floor($hrs/ 24)
        $hrs -= $days * 24
    endif

    local $diff_out = stringformat('%02i Days %02i Hours %02i Minutes %02i Seconds to ' & stringleft($target_date,stringinstr($target_date,' ')), $days, $hrs, $mins, $secs)
    guictrlsetdata($lbl010,$diff_out)
    $warn -= 1
    if mod($warn,$warn_intrvl) = 0 then
        traytip('',$warn_intrvl & ' seconds have passed' & @lf & $diff_out,5)
        ConsoleWrite('Displaying traytip at ' & $diff_out & @LF)
        $display_time = 1
    endif
    if  $display_time = 10 then
        traytip('','',0)
        $display_time = 0
    endif
    if $display_time then $display_time += 1

endfunc

kylomas

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Thank you Kylomas i have no words brother.

Thank you and all the others.

Share this post


Link to post
Share on other sites

noobish,

This is one way to do this, search the forum for other alternatives, including UEZ's code from the OP.

Good Luck,

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

@Kylomas

Thank you a lot you UEZ and all other guys that helped me.

It works great.

In the script you made i want to add some lines from UEZ's code to run an .exe ( autoit script that installs a WP and popups a message etc.) when the time is near to New Year ( 2 hours before for example ) This is a part of the code i try to add in the main script but with no luck however.

UEZ's complete script is

Do
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case $button, $dummy
Run("AutoIt-Script.exe")
EndSwitch
If TimerDiff($iTimer) > $iTimeTrayIcon Then
TrayTip("Information", "Sylvester Party in: " & $sTimeLeft, 10, 1)
$iTimer = TimerInit()
EndIf
Until False

I want to add this in to your main script

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