Jump to content

Using @HOUR


Recommended Posts

I have a script that runs fine if I activate with the Task Scheduler. What I'd like to do is have something in the script that would go look at the time once a minute, and when the hour hits a certain time (number) then the script goes ahead and runs its main duty. From the documentation the @HOUR macro looks like the thing to use for this but am not completely sure. Would it work for what I have described? If so can anyone give me a jumpstart on how to use it. If it wouldn't work then what would you suggest? The tutorials don't seem to cover this though I'm sure this is something simple. Also I did a search but there doesn't seem to have been a posting about this macro in recent history.

TIA

Link to comment
Share on other sites

Well you want to run the script in an infinite loop, so we make a while loop to do that:

While 1
; Code will go here
WEnd

Then we want to check the time, I'm not exactly sure what @HOUR returns (no AutoIt on this computer)

While 1
  ; Check if it's 6 o'clock, simpsons are on then!
  ; NOTE: You'll have to add AM/PM stuff also, just an example
    If @HOUR = 6 Then 
        MsgBox( "","What time is it?", "It's 6 o'clock, time for the Simpsons!")
    EndIf
WEnd
Edited by Insolence
"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

nahh, @Hour returns a 24 hour time, so if you want standard non-army like time, then just do:

While 1
; Check if it's 6 o'clock, simpsons are on then!
; NOTE: You'll have to add AM/PM stuff also, just an example
    If (@HOUR - 12) = 6 Then 
        MsgBox(0,"What time is it?", "It's 6 o'clock, time for the Simpsons!")
    EndIf
WEnd

minus @Hour by 12

EDIT: heres a better example

Do
    Sleep(1000)
Until (@Hour - 12) = 6

;MAIN PART OF PROGRAM GOES HERE...
Edited by layer
FootbaG
Link to comment
Share on other sites

Ok, thanks. The Do Until looks easy enough, I need it to run at 6am so 24 hour format won't bother me a bit. So this should do it for me:

Do

    Sleep(1000)

Until @Hour= 6

I'll try it later when I get home from work.

<{POST_SNAPBACK}>

Timers are fun. :) I like this one personally: It clicks a button once every 5 minutes.

While 1
   Sleep(10)
;;;; start timer
   If Mod(@MIN, 5) = 0 And $mod = 0 Then
      ControlClick($hwndTally, "", $buttonRefresh, $primary, 1)
      $mod = 1
   ElseIf Mod(@MIN, 5) > 0 And $mod = 1 Then
      $mod = 0
   EndIf
;;;; end timer
   $msg = GUIGetMsg()
   . . .
   . . .
   . . . 
WEnd

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

First of all, sorry for reviving this 4 day old post/topic.

I have created a Gui and i would like it to display current time such as the clock commonly found in the bottom right hand of your screen :). How would i do somthing like that?

All my tries so far come up blank and only use the time i opened the aus prog.?

Thanks for any help, and sorry for reviving this(just seems sensible place to ask this.)

[font="Arial"]--------When you go to jail a friend will bve thier to bail you out, but a best friend will be sitting right next to you saying, "D*** we F**ked up!"--------A friend helps you move, but a best friend helps you move dead bodies?Which brings me to my question, what kind of friend are you?[/font]
Link to comment
Share on other sites

First of all, sorry for reviving this 4 day old post/topic.

I have created a Gui and i would like it to display current time such as the clock commonly found in the bottom right hand of your screen :). How would i do somthing like that?

All my tries so far come up blank and only use the time i opened the aus prog.?

Thanks for any help, and sorry for reviving this(just seems sensible place to ask this.)

<{POST_SNAPBACK}>

Something similar to my timer would work, except you'd use the modulus to update your GUI say...every five to ten seconds instead of every 5 minutes.

Assuming your clock is a label on your GUI and that you've already created it...put this in the loop somewhere around where the GUIGetMsg function is. This will update your clock every 5 seconds while the GUI is waiting for input.

If Mod(@Sec, 5) = 0 And $mod = 0 Then
      GUICtrlSetData($labelClock, @hour & ":" & @min)
      $mod = 1
   ElseIf Mod(@Sec, 5) > 0 And $mod = 1 Then
      $mod = 0
   EndIf

Now, the clock will NOT update if you're off of the main GUI. If you want the script to keep updating the main GUI's clock label, regardless of where it is at in the script, use an AdLib() function.

; header
AdLibEnable("_GUIClock")
.
; body 
.
; function list

_GUIClock()
   If Mod(@Sec, 5) = 0 And $mod = 0 Then
      GUICtrlSetData($labelClock, @hour & ":" & @min)
      $mod = 1
   ElseIf Mod(@Sec, 5) > 0 And $mod = 1 Then
      $mod = 0
   EndIf
EndFunc
Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

Once again a revive this:

Gui opens for 1/2Seconds then coses and gives this error

C:\Documents and Settings\jimmydo\Desktop\Unused Desktop Shortcuts\scite4autoit3 2\my work\tv.au3 (62) : ==> Variable used without being declared.:

If Mod(@Sec, 5) = 0 And $mod = 0 Then

If Mod(@Sec, 5) = 0 And ^ ERROR

Where am supposed to declare the $mod at? Not getting this in the least bit!

func _GUIClock()
   If Mod(@Sec, 5) = 0 And $mod = 0 Then
      GUICtrlSetData($labelClock, @hour & ":" & @min)
      $mod = 1
   ElseIf Mod(@Sec, 5) > 0 And $mod = 1 Then
      $mod = 0
   EndIf
endfunc
[font="Arial"]--------When you go to jail a friend will bve thier to bail you out, but a best friend will be sitting right next to you saying, "D*** we F**ked up!"--------A friend helps you move, but a best friend helps you move dead bodies?Which brings me to my question, what kind of friend are you?[/font]
Link to comment
Share on other sites

Put Dim $mod at the top of your script.

<{POST_SNAPBACK}>

Correct, I forgot to mention that....oops. You must define the $mod variable as a global before using this function, otherwise it will crash. Just put GLOBAL $mod = 0 or what Slim said. Either way it works, I just prefer to specifiy the word "global"

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

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