Jump to content

Auto-pc shutdown - countdown


Recommended Posts

Hello. I'd like to write simple pc-shutdown. It's working for me, but I'd like to add something like "counter", to display how much time is left till shut down. However, I don't know how to do it. For instance, when it's 10pm and i want to shutdown my pc at 1am - its 3 hours interval. How to count it in mathematically way? This is my code made so far:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=d:\projekty autoit\projekty\time-closer\form1.kxf
$Form1_1 = GUICreate("Remote PC Shutdown", 312, 326, 192, 124)
$Group1 = GUICtrlCreateGroup("The time of shutdown", 8, 8, 185, 89)
$godz = GUICtrlCreateInput("", 64, 32, 57, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER))
$min = GUICtrlCreateInput("", 64, 64, 57, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER))
$Label1 = GUICtrlCreateLabel("Hour:", 16, 32, 46, 17)
$Label2 = GUICtrlCreateLabel("Minute:", 16, 64, 36, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Clock", 200, 8, 107, 89)
$Labelhour = GUICtrlCreateLabel("", 208, 40, 42, 35)
GUICtrlSetFont(-1, 25, 400, 0, "MS Sans Serif")
$Label4 = GUICtrlCreateLabel(":", 252, 40, 9, 35)
GUICtrlSetFont(-1, 25, 400, 0, "MS Sans Serif")
$LabelMinute = GUICtrlCreateLabel("", 262, 40, 40, 35)
GUICtrlSetFont(-1, 25, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Start = GUICtrlCreateButton("Start", 200, 224, 107, 40, $WS_GROUP)
$Group3 = GUICtrlCreateGroup("The way of shutdown", 8, 104, 185, 217)
$Radio1 = GUICtrlCreateRadio("Logoff", 24, 128, 113, 17)
$Radio2 = GUICtrlCreateRadio("Shutdown", 24, 152, 113, 17)
$Radio3 = GUICtrlCreateRadio("Reboot", 24, 176, 113, 17)
$Radio4 = GUICtrlCreateRadio("Force", 24, 200, 113, 17)
$Radio5 = GUICtrlCreateRadio("Power down", 24, 224, 113, 17)
$Radio6 = GUICtrlCreateRadio("Force if hung", 24, 248, 113, 17)
$Radio7 = GUICtrlCreateRadio("Standby", 24, 272, 113, 17)
$Radio8 = GUICtrlCreateRadio("Hibernate", 24, 296, 113, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group4 = GUICtrlCreateGroup("Time left", 200, 104, 107, 89)
$GodzLEFT = GUICtrlCreateLabel("15", 208, 136, 38, 41)
GUICtrlSetFont(-1, 25, 400, 0, "MS Sans Serif")
$Label5 = GUICtrlCreateLabel(":", 248, 136, 13, 41)
GUICtrlSetFont(-1, 25, 400, 0, "MS Sans Serif")
$MinLEFT = GUICtrlCreateLabel("15", 256, 136, 38, 41)
GUICtrlSetFont(-1, 25, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Stop = GUICtrlCreateButton("Stop", 200, 272, 107, 41, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $x
AdlibRegister("clock", 1000)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Start
            If GUICtrlRead($godz) <> 0 And GUICtrlRead($min) <> 0 Then
                podmianaGODZIN()
                podmianaMINUT()
                If GUICtrlGetState($Radio1) = $GUI_CHECKED Then
                    $x = 0
                    AdlibRegister("off", 1000)
                ElseIf GUICtrlGetState($Radio2) = $GUI_CHECKED Then
                    $x = 1
                    AdlibRegister("off", 1000)
                ElseIf GUICtrlGetState($Radio3) = $GUI_CHECKED Then
                    $x = 2
                    AdlibRegister("off", 1000)
                ElseIf GUICtrlGetState($Radio4) = $GUI_CHECKED Then
                    $x = 4
                    AdlibRegister("off", 1000)
                ElseIf GUICtrlGetState($Radio5) = $GUI_CHECKED Then
                    $x = 8
                    AdlibRegister("off", 1000)
                ElseIf GUICtrlGetState($Radio6) = $GUI_CHECKED Then
                    $x = 16
                    AdlibRegister("off", 1000)
                ElseIf GUICtrlGetState($Radio7) = $GUI_CHECKED Then
                    $x = 32
                    AdlibRegister("off", 1000)
                ElseIf GUICtrlGetState($Radio8) = $GUI_CHECKED Then
                    $x = 64
                    AdlibRegister("off", 1000)
                EndIf
            EndIf
        Case $Stop
            AdlibUnRegister("off")
    EndSwitch
WEnd

Func clock()
    GUICtrlSetData($Labelhour, @HOUR)
    GUICtrlSetData($LabelMinute, @MIN)
EndFunc   ;==>zegar


Func off()
    If GUICtrlRead($godz) = @HOUR And GUICtrlRead($min) = @MIN Then
        Shutdown($x)
    EndIf
EndFunc   ;==>off


Func hourSWAP()
    If GUICtrlRead($godz) = 1 Then
        GUICtrlSetData($godz, "01")
    ElseIf GUICtrlRead($godz) = 2 Then
        GUICtrlSetData($godz, "02")
    ElseIf GUICtrlRead($godz) = 3 Then
        GUICtrlSetData($godz, "03")
    ElseIf GUICtrlRead($godz) = 4 Then
        GUICtrlSetData($godz, "04")
    ElseIf GUICtrlRead($godz) = 5 Then
        GUICtrlSetData($godz, "05")
    ElseIf GUICtrlRead($godz) = 6 Then
        GUICtrlSetData($godz, "06")
    ElseIf GUICtrlRead($godz) = 7 Then
        GUICtrlSetData($godz, "07")
    ElseIf GUICtrlRead($godz) = 8 Then
        GUICtrlSetData($godz, "08")
    ElseIf GUICtrlRead($godz) = 9 Then
        GUICtrlSetData($godz, "09")
    EndIf
EndFunc


Func minuteSWAP()
    If GUICtrlRead($min) = 1 Then
        GUICtrlSetData($min, "01")
    ElseIf GUICtrlRead($min) = 2 Then
        GUICtrlSetData($min, "02")
    ElseIf GUICtrlRead($min) = 3 Then
        GUICtrlSetData($min, "03")
    ElseIf GUICtrlRead($min) = 4 Then
        GUICtrlSetData($min, "04")
    ElseIf GUICtrlRead($min) = 5 Then
        GUICtrlSetData($min, "05")
    ElseIf GUICtrlRead($min) = 6 Then
        GUICtrlSetData($min, "06")
    ElseIf GUICtrlRead($min) = 7 Then
        GUICtrlSetData($min, "07")
    ElseIf GUICtrlRead($min) = 8 Then
        GUICtrlSetData($min, "08")
    ElseIf GUICtrlRead($min) = 9 Then
        GUICtrlSetData($min, "09")
    EndIf
EndFunc
Link to comment
Share on other sites

Hello, it's me again. I have another problem. Don't know how to change seconds into this format: HH:MM:SS ? It's kind a complicated for me, because there is 3600 seconds in hours and the rest from splitting is in 1 to 100 format (if u know what i mean, dunno how to explain it more clearly). Any suggestions? This is my script:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <Date.au3>
#Region ### START Koda GUI section ### Form=
$Form1_1 = GUICreate("Remote PC Shutdown", 313, 344, 192, 124)
$Group1 = GUICtrlCreateGroup("Godzina wyƂączenia komputera", 8, 8, 185, 105)
$hour = GUICtrlCreateInput("", 72, 32, 57, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER))
$min = GUICtrlCreateInput("", 72, 56, 57, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER))
$sec = GUICtrlCreateInput("", 72, 80, 57, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER))
$Label1 = GUICtrlCreateLabel("Hour:", 16, 32, 46, 17)
$Label2 = GUICtrlCreateLabel("Minute:", 16, 56, 36, 17)
$Label3 = GUICtrlCreateLabel("Second:", 16, 80, 50, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("clock", 200, 8, 107, 105)
$LabelHour = GUICtrlCreateLabel("", 208, 40, 42, 35)
GUICtrlSetFont(-1, 25, 400, 0, "MS Sans Serif")
$Label4 = GUICtrlCreateLabel(":", 252, 40, 9, 35)
GUICtrlSetFont(-1, 25, 400, 0, "MS Sans Serif")
$LabelMinute = GUICtrlCreateLabel("", 262, 40, 40, 35)
GUICtrlSetFont(-1, 25, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Start = GUICtrlCreateButton("Start", 200, 232, 107, 40, $WS_GROUP)
$Group3 = GUICtrlCreateGroup("The way of shutdown", 8, 120, 185, 217)
$Radio1 = GUICtrlCreateRadio("Logoff", 24, 144, 113, 17)
$Radio2 = GUICtrlCreateRadio("Shutdown", 24, 168, 113, 17)
$Radio3 = GUICtrlCreateRadio("Reboot", 24, 192, 113, 17)
$Radio4 = GUICtrlCreateRadio("Force", 24, 216, 113, 17)
$Radio5 = GUICtrlCreateRadio("Power down", 24, 240, 113, 17)
$Radio6 = GUICtrlCreateRadio("Force if hung", 24, 264, 113, 17)
$Radio7 = GUICtrlCreateRadio("Standby", 24, 288, 113, 17)
$Radio8 = GUICtrlCreateRadio("Hibernate", 24, 312, 113, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group4 = GUICtrlCreateGroup("Time left", 200, 120, 107, 89)
$hourLEFT = GUICtrlCreateLabel("15", 208, 152, 38, 41)
GUICtrlSetFont(-1, 25, 400, 0, "MS Sans Serif")
$Label5 = GUICtrlCreateLabel(":", 248, 152, 13, 41)
GUICtrlSetFont(-1, 25, 400, 0, "MS Sans Serif")
$MinLEFT = GUICtrlCreateLabel("15", 256, 152, 38, 41)
GUICtrlSetFont(-1, 25, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Stop = GUICtrlCreateButton("Stop", 200, 288, 107, 41, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $x
AdlibRegister("clock", 1000)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Start
            If GUICtrlRead($hour) <> 0 And GUICtrlRead($min) <> 0 Then
                HOURSswap()
                MINUTESswap()
                If GUICtrlGetState($Radio1) = $GUI_CHECKED Then
                    $x = 0
                    AdlibRegister("off", 1000)
                ElseIf GUICtrlGetState($Radio2) = $GUI_CHECKED Then
                    $x = 1
                    AdlibRegister("off", 1000)
                ElseIf GUICtrlGetState($Radio3) = $GUI_CHECKED Then
                    $x = 2
                    AdlibRegister("off", 1000)
                ElseIf GUICtrlGetState($Radio4) = $GUI_CHECKED Then
                    $x = 4
                    AdlibRegister("off", 1000)
                ElseIf GUICtrlGetState($Radio5) = $GUI_CHECKED Then
                    $x = 8
                    AdlibRegister("off", 1000)
                ElseIf GUICtrlGetState($Radio6) = $GUI_CHECKED Then
                    $x = 16
                    AdlibRegister("off", 1000)
                ElseIf GUICtrlGetState($Radio7) = $GUI_CHECKED Then
                    $x = 32
                    AdlibRegister("off", 1000)
                ElseIf GUICtrlGetState($Radio8) = $GUI_CHECKED Then
                    $x = 64
                    AdlibRegister("off", 1000)
                EndIf
            EndIf
        Case $Stop
            ;AdlibUnRegister("off")
counter()
    EndSwitch
WEnd

Func clock()
    GUICtrlSetData($LabelHour, @HOUR)
    GUICtrlSetData($LabelMinute, @MIN)
EndFunc   ;==>clock


Func off()
    If GUICtrlRead($hour) = @HOUR And GUICtrlRead($min) = @MIN Then
        Shutdown($x)
    EndIf
EndFunc   ;==>off


Func HOURSswap()
    If GUICtrlRead($hour) = 1 Then
        GUICtrlSetData($hour, "01")
    ElseIf GUICtrlRead($hour) = 2 Then
        GUICtrlSetData($hour, "02")
    ElseIf GUICtrlRead($hour) = 3 Then
        GUICtrlSetData($hour, "03")
    ElseIf GUICtrlRead($hour) = 4 Then
        GUICtrlSetData($hour, "04")
    ElseIf GUICtrlRead($hour) = 5 Then
        GUICtrlSetData($hour, "05")
    ElseIf GUICtrlRead($hour) = 6 Then
        GUICtrlSetData($hour, "06")
    ElseIf GUICtrlRead($hour) = 7 Then
        GUICtrlSetData($hour, "07")
    ElseIf GUICtrlRead($hour) = 8 Then
        GUICtrlSetData($hour, "08")
    ElseIf GUICtrlRead($hour) = 9 Then
        GUICtrlSetData($hour, "09")
    EndIf
EndFunc   ;==>HOURSswap


Func MINUTESswap()
    If GUICtrlRead($min) = 1 Then
        GUICtrlSetData($min, "01")
    ElseIf GUICtrlRead($min) = 2 Then
        GUICtrlSetData($min, "02")
    ElseIf GUICtrlRead($min) = 3 Then
        GUICtrlSetData($min, "03")
    ElseIf GUICtrlRead($min) = 4 Then
        GUICtrlSetData($min, "04")
    ElseIf GUICtrlRead($min) = 5 Then
        GUICtrlSetData($min, "05")
    ElseIf GUICtrlRead($min) = 6 Then
        GUICtrlSetData($min, "06")
    ElseIf GUICtrlRead($min) = 7 Then
        GUICtrlSetData($min, "07")
    ElseIf GUICtrlRead($min) = 8 Then
        GUICtrlSetData($min, "08")
    ElseIf GUICtrlRead($min) = 9 Then
        GUICtrlSetData($min, "09")
    EndIf
EndFunc   ;==>MINUTESswap


Func counter()
$iDateCalc = _DateDiff( 's',_NowCalc(),@YEAR & "/" & @MON & "/" & @MDAY & " " & GUICtrlRead($hour) & ":" & GUICtrlRead($min) & ":" & GUICtrlRead($sec))
MsgBox(0,"lol",$iDateCalc / 60)
MsgBox(0,"lol", @YEAR & "/" & @MON & "/" & @MDAY & " " & GUICtrlRead($hour) & ":" & GUICtrlRead($min) & ":" & GUICtrlRead($sec))
EndFunc
Link to comment
Share on other sites

Maybe this helps a bit? It probably isn't exactly what you want, but it should get you going in the right direction.. The 6732 * 1000 part converts 6732 ticks (milliseconds) to seconds.

#include <Date.au3>
Local $Hour, $Mins, $Secs
_TicksToTime(6732 * 1000, $Hour, $Mins, $Secs)
ConsoleWrite($Hour & ":" & $Mins & ":" & $Secs & @LF)

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

Hello, it's me again. I have another problem. Don't know how to change seconds into this format: HH:MM:SS ? It's kind a complicated for me, because there is 3600 seconds in hours and the rest from splitting is in 1 to 100 format (if u know what i mean, dunno how to explain it more clearly). Any suggestions? This is my script:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <Date.au3>
#Region ### START Koda GUI section ### Form=
$Form1_1 = GUICreate("Remote PC Shutdown", 313, 344, 192, 124)
$Group1 = GUICtrlCreateGroup("Godzina wyƂączenia komputera", 8, 8, 185, 105)
$hour = GUICtrlCreateInput("", 72, 32, 57, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER))
$min = GUICtrlCreateInput("", 72, 56, 57, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER))
$sec = GUICtrlCreateInput("", 72, 80, 57, 21, BitOR($ES_AUTOHSCROLL,$ES_NUMBER))
$Label1 = GUICtrlCreateLabel("Hour:", 16, 32, 46, 17)
$Label2 = GUICtrlCreateLabel("Minute:", 16, 56, 36, 17)
$Label3 = GUICtrlCreateLabel("Second:", 16, 80, 50, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("clock", 200, 8, 107, 105)
$LabelHour = GUICtrlCreateLabel("", 208, 40, 42, 35)
GUICtrlSetFont(-1, 25, 400, 0, "MS Sans Serif")
$Label4 = GUICtrlCreateLabel(":", 252, 40, 9, 35)
GUICtrlSetFont(-1, 25, 400, 0, "MS Sans Serif")
$LabelMinute = GUICtrlCreateLabel("", 262, 40, 40, 35)
GUICtrlSetFont(-1, 25, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Start = GUICtrlCreateButton("Start", 200, 232, 107, 40, $WS_GROUP)
$Group3 = GUICtrlCreateGroup("The way of shutdown", 8, 120, 185, 217)
$Radio1 = GUICtrlCreateRadio("Logoff", 24, 144, 113, 17)
$Radio2 = GUICtrlCreateRadio("Shutdown", 24, 168, 113, 17)
$Radio3 = GUICtrlCreateRadio("Reboot", 24, 192, 113, 17)
$Radio4 = GUICtrlCreateRadio("Force", 24, 216, 113, 17)
$Radio5 = GUICtrlCreateRadio("Power down", 24, 240, 113, 17)
$Radio6 = GUICtrlCreateRadio("Force if hung", 24, 264, 113, 17)
$Radio7 = GUICtrlCreateRadio("Standby", 24, 288, 113, 17)
$Radio8 = GUICtrlCreateRadio("Hibernate", 24, 312, 113, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group4 = GUICtrlCreateGroup("Time left", 200, 120, 107, 89)
$hourLEFT = GUICtrlCreateLabel("15", 208, 152, 38, 41)
GUICtrlSetFont(-1, 25, 400, 0, "MS Sans Serif")
$Label5 = GUICtrlCreateLabel(":", 248, 152, 13, 41)
GUICtrlSetFont(-1, 25, 400, 0, "MS Sans Serif")
$MinLEFT = GUICtrlCreateLabel("15", 256, 152, 38, 41)
GUICtrlSetFont(-1, 25, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Stop = GUICtrlCreateButton("Stop", 200, 288, 107, 41, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $x
AdlibRegister("clock", 1000)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Start
            If GUICtrlRead($hour) <> 0 And GUICtrlRead($min) <> 0 Then
                HOURSswap()
                MINUTESswap()
                If GUICtrlGetState($Radio1) = $GUI_CHECKED Then
                    $x = 0
                    AdlibRegister("off", 1000)
                ElseIf GUICtrlGetState($Radio2) = $GUI_CHECKED Then
                    $x = 1
                    AdlibRegister("off", 1000)
                ElseIf GUICtrlGetState($Radio3) = $GUI_CHECKED Then
                    $x = 2
                    AdlibRegister("off", 1000)
                ElseIf GUICtrlGetState($Radio4) = $GUI_CHECKED Then
                    $x = 4
                    AdlibRegister("off", 1000)
                ElseIf GUICtrlGetState($Radio5) = $GUI_CHECKED Then
                    $x = 8
                    AdlibRegister("off", 1000)
                ElseIf GUICtrlGetState($Radio6) = $GUI_CHECKED Then
                    $x = 16
                    AdlibRegister("off", 1000)
                ElseIf GUICtrlGetState($Radio7) = $GUI_CHECKED Then
                    $x = 32
                    AdlibRegister("off", 1000)
                ElseIf GUICtrlGetState($Radio8) = $GUI_CHECKED Then
                    $x = 64
                    AdlibRegister("off", 1000)
                EndIf
            EndIf
        Case $Stop
            ;AdlibUnRegister("off")
counter()
    EndSwitch
WEnd

Func clock()
    GUICtrlSetData($LabelHour, @HOUR)
    GUICtrlSetData($LabelMinute, @MIN)
EndFunc   ;==>clock


Func off()
    If GUICtrlRead($hour) = @HOUR And GUICtrlRead($min) = @MIN Then
        Shutdown($x)
    EndIf
EndFunc   ;==>off


Func HOURSswap()
    If GUICtrlRead($hour) = 1 Then
        GUICtrlSetData($hour, "01")
    ElseIf GUICtrlRead($hour) = 2 Then
        GUICtrlSetData($hour, "02")
    ElseIf GUICtrlRead($hour) = 3 Then
        GUICtrlSetData($hour, "03")
    ElseIf GUICtrlRead($hour) = 4 Then
        GUICtrlSetData($hour, "04")
    ElseIf GUICtrlRead($hour) = 5 Then
        GUICtrlSetData($hour, "05")
    ElseIf GUICtrlRead($hour) = 6 Then
        GUICtrlSetData($hour, "06")
    ElseIf GUICtrlRead($hour) = 7 Then
        GUICtrlSetData($hour, "07")
    ElseIf GUICtrlRead($hour) = 8 Then
        GUICtrlSetData($hour, "08")
    ElseIf GUICtrlRead($hour) = 9 Then
        GUICtrlSetData($hour, "09")
    EndIf
EndFunc   ;==>HOURSswap


Func MINUTESswap()
    If GUICtrlRead($min) = 1 Then
        GUICtrlSetData($min, "01")
    ElseIf GUICtrlRead($min) = 2 Then
        GUICtrlSetData($min, "02")
    ElseIf GUICtrlRead($min) = 3 Then
        GUICtrlSetData($min, "03")
    ElseIf GUICtrlRead($min) = 4 Then
        GUICtrlSetData($min, "04")
    ElseIf GUICtrlRead($min) = 5 Then
        GUICtrlSetData($min, "05")
    ElseIf GUICtrlRead($min) = 6 Then
        GUICtrlSetData($min, "06")
    ElseIf GUICtrlRead($min) = 7 Then
        GUICtrlSetData($min, "07")
    ElseIf GUICtrlRead($min) = 8 Then
        GUICtrlSetData($min, "08")
    ElseIf GUICtrlRead($min) = 9 Then
        GUICtrlSetData($min, "09")
    EndIf
EndFunc   ;==>MINUTESswap


Func counter()
$iDateCalc = _DateDiff( 's',_NowCalc(),@YEAR & "/" & @MON & "/" & @MDAY & " " & GUICtrlRead($hour) & ":" & GUICtrlRead($min) & ":" & GUICtrlRead($sec))
MsgBox(0,"lol",$iDateCalc / 60)
MsgBox(0,"lol", @YEAR & "/" & @MON & "/" & @MDAY & " " & GUICtrlRead($hour) & ":" & GUICtrlRead($min) & ":" & GUICtrlRead($sec))
EndFunc

This is simple you need three vars.

var 1 = diffdate for hours

var 2 = diffdate for minutes - var 1 *unit conversion

var 3 = diff date for seconds - var 2 * unit conversion + var 1* unit conversion

HH:MM:SS

Read the date.au3 include file and the autoit function entry for _DiffDate. It will help you out.

Edited by targeter
Link to comment
Share on other sites

LOL. I don't get it really, but it's working ;) Something like this, yea? I have to read in this code to fully understand it :)

$iDateCalc1 = _DateDiff( 'h',_NowCalc(),@YEAR & "/" & @MON & "/" & @MDAY & " " & GUICtrlRead($godz) & ":" & GUICtrlRead($min) & ":" & GUICtrlRead($sec)) 
$iDateCalc2 = _DateDiff( 'n',_NowCalc(),@YEAR & "/" & @MON & "/" & @MDAY & " " & GUICtrlRead($godz) & ":" & GUICtrlRead($min) & ":" & GUICtrlRead($sec)) 
$iDateCalc3 = _DateDiff( 's',_NowCalc(),@YEAR & "/" & @MON & "/" & @MDAY & " " & GUICtrlRead($godz) & ":" & GUICtrlRead($min) & ":" & GUICtrlRead($sec))  
$HH = $iDateCalc1 
$MM = $iDateCalc2 - $iDateCalc1 * 60 
$SS = $iDateCalc3 - $iDateCalc2 * 60 + $iDateCalc1 * 3600 
MsgBox(0,"Info", "PozostaƂy czas to: " & $HH & ":" & $MM & ":" & $SS)

///EDIT

Ohh no, it doesn't work corectly. Sometimes it shows for instance 72 seconds. Especially when hour is > 12 pm and minutes are bigger than 20.

Edited by zwierzak
Link to comment
Share on other sites

LOL. I don't get it really, but it's working ;) Something like this, yea? I have to read in this code to fully understand it :)

$iDateCalc1 = _DateDiff( 'h',_NowCalc(),@YEAR & "/" & @MON & "/" & @MDAY & " " & GUICtrlRead($godz) & ":" & GUICtrlRead($min) & ":" & GUICtrlRead($sec)) 
$iDateCalc2 = _DateDiff( 'n',_NowCalc(),@YEAR & "/" & @MON & "/" & @MDAY & " " & GUICtrlRead($godz) & ":" & GUICtrlRead($min) & ":" & GUICtrlRead($sec)) 
$iDateCalc3 = _DateDiff( 's',_NowCalc(),@YEAR & "/" & @MON & "/" & @MDAY & " " & GUICtrlRead($godz) & ":" & GUICtrlRead($min) & ":" & GUICtrlRead($sec))  
$HH = $iDateCalc1 
$MM = $iDateCalc2 - $iDateCalc1 * 60 
$SS = $iDateCalc3 - $iDateCalc2 * 60 + $iDateCalc1 * 3600 
MsgBox(0,"Info", "PozostaƂy czas to: " & $HH & ":" & $MM & ":" & $SS)

///EDIT

Ohh no, it doesn't work corectly. Sometimes it shows for instance 72 seconds. Especially when hour is > 12 pm and minutes are bigger than 20.

something is going on separate from the vars. I had something written earlier that works. very similar code.

DateDiff returns the units of difference based on the unit passed to the function. If the difference is 1 hour, that 1 hour is also represented if you request minutes or seconds. This is why you need to subtract them. Do you understand? It is like double counting.

Now as for your time problem, are you giving the function a 12 or 24 hour format? That is your problem. Read Date.au3. Your answer is there.

Link to comment
Share on other sites

A while ago there was a guy that had trouble getting a countdown till shutdown to work aswell. Sadly the Topic title wasn't as descriptive as yours so it took me a while to find, but you might be able to get a few idea's over here.

It shows a different approach, which will be usefull, or confusing. Either way ;)

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