Sign in to follow this  
Followers 0
reg_hack

Execute Function on Time

7 posts in this topic

Hi,

I've written a script, where users can write a time into a field in the GUI.On the Time a funktion should run.

With GUICtrlRead I read the User-Time from the input-field.

Later I want check the actually time with _NowTime and compare it with the usertime.

If it ist the same, the function should run on.

Obviously the Time from _NowTime and the Input-Field-Variable-Time are not the same

format although if you write it in a message-box its hh:mm:ss.

Can somebody tell me, how I can compare the two Times? Or should I fix the problem on a totaly other way?

test123.au3

Share this post


Link to post
Share on other sites



Hi,

I've written a script, where users can write a time into a field in the GUI.On the Time a funktion should run.

With GUICtrlRead I read the User-Time from the input-field.

Later I want check the actually time with _NowTime and compare it with the usertime.

If it ist the same, the function should run on.

Obviously the Time from _NowTime and the Input-Field-Variable-Time are not the same

format although if you write it in a message-box its hh:mm:ss.

Can somebody tell me, how I can compare the two Times? Or should I fix the problem on a totaly other way?

Try this:

Global $punkt = (".")
Global $startip1, $startip2,$startip3,$startip4,$endIP01,$endIP02,$endIP03,$endIP04
Global $nowtime
Global $runtime
Global $DoItAt
while 1
   $run = GUIGetMsg()
   IF $run = $cancel Then ExitLoop 
   IF $run = $GUI_EVENT_CLOSE Then ExitLoop
   IF $run = $execute Then
      $runtime = StringSplit ( GUICtrlRead($input_scanzeit), ':' )

; This is to insure we pass _TimeToTicks three numbers in case hh:mm is entered (with no seconds)
      If UBound($runtime) <> 4 Then
         ReDim $runtime[4]
      EndIf
      For $i = 1 To 3
         If $runtime[$i] = '' Then
            $runtime[$i] = 0
         EndIf
      Next
      $DoItAt = _TimeToTicks ( $runtime[1], $runtime[2], $runtime[3] )

      $startip1 = GUICtrlRead($input_startip_1)
      $startip2 = GUICtrlRead($input_startip_2)
      $startip3 = GUICtrlRead($input_startip_3)
      $startip4 = GUICtrlRead($input_startip_4)
      $endIP01 = GUICtrlRead($input_zielip_1)
      $endIP02 = GUICtrlRead($input_zielip_2)
      $endIP03 = GUICtrlRead($input_zielip_3)
      $endIP04 = GUICtrlRead($input_zielip_4)
      ExitLoop
      EndIf                             
WEnd

GUISetState ( @SW_HIDE )

While _TimeToTicks() < $DoItAt
      Sleep ( 1000 )
WEnd

exec_ping()

Exit

I moved reading the input fields which allows the GUI to close while waiting.

Hope this helps.

Share this post


Link to post
Share on other sites

Nice Work Jerry!


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Nice Work Jerry!

It looks great. But if I replace my code with yours, i get the warning:

... test123.au3(72,20) : ERROR: _TimeToTicks() called with wrong number of args.

While _TimeToTicks()

~~~~~~~~~~~~~~~~~~~^

C:\Programme\AutoIt3\Include\date.au3(1150,43) : REF: definition of _TimeToTicks().

Func _TimeToTicks($iHours, $iMins, $iSecs)

test456.au3

Share this post


Link to post
Share on other sites

It looks great. But if I replace my code with yours, i get the warning:

... test123.au3(72,20) : ERROR: _TimeToTicks() called with wrong number of args.

While _TimeToTicks()

~~~~~~~~~~~~~~~~~~~^

C:\Programme\AutoIt3\Include\date.au3(1150,43) : REF: definition of _TimeToTicks().

Func _TimeToTicks($iHours, $iMins, $iSecs)

The UDF has probably been updated - I'm running Beta 101. The Beta Help defines the function as:

_TimeToTicks([$iHours = @Hour, [$iMins = @Min, [$iSecs = @Sec]]])

That is, if it's not called with any parameters, it will use the current time as the default.

Just change the line to:

While _TimeToTicks( @Hour, @Min, @Sec) < $DoItAt

and it should work fine with the production UDF.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Try this:

#include <GUIConstants.au3>
#include <file.au3>
#include <date.au3>
Dim $TimeValue
Dim $DoItAt

$punkt = (".")
;################################## GUI ###############################################

GUICreate("Active-Host Pinger V2.0" , 300, 400)
GUISetState()

GUICtrlCreateLabel ("1st-IP", 25, 75)
$input_startip_1 = GuiCtrlCreateInput("xxx", 20, 95, 50)
$input_startip_2 = GuiCtrlCreateInput("xxx", 90, 95, 50)
$input_startip_3 = GuiCtrlCreateInput("xxx", 160, 95, 50)
$input_startip_4 = GuiCtrlCreateInput("xxx", 230, 95, 50)

GUICtrlCreateLabel ("Last-IP", 25, 125)
$input_zielip_1 = GuiCtrlCreateInput("xxx", 20, 145, 50)
$input_zielip_2 = GuiCtrlCreateInput("xxx", 90, 145, 50)
$input_zielip_3 = GuiCtrlCreateInput("xxx", 160, 145, 50)
$input_zielip_4 = GuiCtrlCreateInput("xxx", 230, 145, 50)


GUICtrlCreateLabel ("Scantime", 25, 200)
$input_scanzeit = GUICtrlCreateInput("hh:mm:ss", 20, 220, 120)


$execute = GUICtrlCreateButton("Run", 45, 350, 100, 25)
$cancel = GUICtrlCreateButton("Cancel",155 , 350, 100, 25)



;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Global $punkt = (".")
Global $startip1, $startip2,$startip3,$startip4,$endIP01,$endIP02,$endIP03,$endIP04
Global $nowtime
Global $runtime
Global $DoItAt
while 1
   $run = GUIGetMsg()
   IF $run = $cancel Then ExitLoop 
   IF $run = $GUI_EVENT_CLOSE Then ExitLoop
   IF $run = $execute Then
      $DoItAt = GUICtrlRead($input_scanzeit)

      $startip1 = GUICtrlRead($input_startip_1)
      $startip2 = GUICtrlRead($input_startip_2)
      $startip3 = GUICtrlRead($input_startip_3)
      $startip4 = GUICtrlRead($input_startip_4)
      $endIP01 = GUICtrlRead($input_zielip_1)
      $endIP02 = GUICtrlRead($input_zielip_2)
      $endIP03 = GUICtrlRead($input_zielip_3)
      $endIP04 = GUICtrlRead($input_zielip_4)
      ExitLoop
    EndIf                               
WEnd

GUISetState ( @SW_HIDE )

While $TimeValue < $DoItAt
      Sleep ( 1000 )
      $CheckHour = @HOUR
      $CheckMin = @MIN
      $CheckSec = @SEC
      $TimeValue = $CheckHour & ":" & $CheckMin & ":" & $CheckSec
      ToolTip('Current Time Value = ' & $TimeValue & @CRLF & 'Time to Initiate Value = ' & $DoItAt, 0, 0)
WEnd

exec_ping()

Exit
;------------------------------------- Ping-Function ---------------------------------------
Func exec_ping()
    Local $startip1, $startip2,$startip3,$startip4,$endIP01,$endIP02,$endIP03,$endIP04
    $startip1 = GUICtrlRead($input_startip_1)                                       
    $startip2 = GUICtrlRead($input_startip_2)                                       
    $startip3 = GUICtrlRead($input_startip_3)                                       
    $startip4 = GUICtrlRead($input_startip_4)                                       
    $endIP01 = GUICtrlRead($input_zielip_1)                                         
    $endIP02 = GUICtrlRead($input_zielip_2)                                         
    $endIP03 = GUICtrlRead($input_zielip_3)                                         
    $endIP04 = GUICtrlRead($input_zielip_4)                                         
    

        $datei = FileOpen("hostpinger-v2_log.txt", 1)       
            While ($startip4 < $endIP04)    
                                
                $pingIP = ($startip1&$punkt&$startip2&$punkt&$startip3&$punkt&$startip4)
                $endIP = ($endIP01&$punkt&$endIP02&$punkt&$endIP03&$punkt&$endIP04)     
;----------------------------------------------------------------------------------------------------------------------------------         
                $report = Ping($pingIP, 2000)                       
;----------------------------------------------------------------------------------------------------------------------------------
                    If $report > 0 Then
                        filewrite($datei, $pingIP & @CRLF)          
                    EndIf               
                    
                $startip4 = ($startip4+1)
            WEnd
        FileClose($datei)
EndFunc

Edit: Just an edit :lmao:

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Both versions are perfect. Thank you very much.

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