Jump to content

[Resolved] How to get a tray script that sends time to clipboard ...


 Share

Recommended Posts

I have something weird coming up that I now know I've run into before. I have a script that resides in the systray that I can use to launch items, etc. One of its functions is to access date/time, in specific formats, so that I use that to append journal entries in an ongoing manner in a program I have. I'll update it every time I have a new entry.

Just now, I needed to append a note and the append was to have put in the current time. It came out as 09h48, which was about the time that I launched this script. When I use the back up feature in this same script, the current time does come out, but this "time to clipboard" time definitely is not.

The syntax the script calls on is this:

$Info4 = @YEAR & "." & @MON & "." & @MDAY & "." & $ShortDayMyFormat & "; " & @HOUR & "h" & @MIN & "m" & @SEC & "s"

but it takes the launch time only and sticks with it. I re-launched this script and am now going to invoke the feature. Yup, still showing the launch time:

14h42

whereas right now my time is 14h51.

How do we get the date/time to refresh pls each time before sending to the clipboard?

Thanks. :D

Edited by Diana (Cda)
Link to comment
Share on other sites

In lieu of the rest of the code being posted, I can only guess your doing something silly like assigning a variable to a return value (or macro) and expecting the variable to be re-updated whenever you reference it...

Consider something like-

$Seconds=@SEC
Sleep(2000)
MsgBox(0,"Example","Two seconds ago the value of @Sec was '"& $Seconds&"' but right NOW it's '"&@SEC&"'")

Or something else could be wrong...It's hard to say with such little context...

Link to comment
Share on other sites

I have something weird coming up that I now know I've run into before. I have a script that resides in the systray that I can use to launch items, etc. One of its functions is to access date/time, in specific formats, so that I use that to append journal entries in an ongoing manner in a program I have. I'll update it every time I have a new entry.

Just now, I needed to append a note and the append was to have put in the current time. It came out as 09h48, which was about the time that I launched this script. When I use the back up feature in this same script, the current time does come out, but this "time to clipboard" time definitely is not.

The syntax the script calls on is this:

$Info4 = @YEAR & "." & @MON & "." & @MDAY & "." & $ShortDayMyFormat & "; " & @HOUR & "h" & @MIN & "m" & @SEC & "s"

but it takes the launch time only and sticks with it. I re-launched this script and am now going to invoke the feature. Yup, still showing the launch time:

14h42

whereas right now my time is 14h51.

How do we get the date/time to refresh pls each time before sending to the clipboard?

Thanks. :D

When is it sent to the Clipboard? What is your loop to update it? Perhaps AdLibEnable() or AdLibRegister() (Beta)?

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

You are only running this line one time.

$Info4 = @YEAR & "." & @MON & "." & @MDAY & "." & $ShortDayMyFormat & "; " & @HOUR & "h" & @MIN & "m" & @SEC & "s"

Maybe because you are expecting the string to be re-evaluated every time, but what matters is that it's not right. 8)

Follow this prototype every time and you should be ok:

Func _ClipPutTime()
   $Info4 = @YEAR & "." & @MON & "." & @MDAY & "." & $ShortDayMyFormat & "; " & @HOUR & "h" & @MIN & "m" & @SEC & "s"
   ClipPut($Info4)
EndFunc
Edited by Manadar
Link to comment
Share on other sites

Manadar, thank you! That must be it. I already had something nearly identical to you, it's just the location of the components. You put the variable _inside_ the function. I had it outside, nearer the top, for ease of use. I'm guessing that outside the function, the information isn't being refreshed. I have no idea why this might be but it must be so. I didn't notice for sure before because this is the first time I kept the script resident in the systray.

So although this doesn't work:

$Info4      = @YEAR & "." & @MON & "." & @MDAY & "." & $ShortDayMyFormat & "; " & @HOUR & "h" & @MIN & "m" & @SEC & "s"
... (other parts of script)
Func _Info4()
    ClipPut($Info4)
    Beep(3500, 15)
EndFunc

This _does_ seem to work:

Func _Info4()
    $Info4      = @YEAR & "." & @MON & "." & @MDAY & "." & $ShortDayMyFormat & "; " & @HOUR & "h" & @MIN & "m" & @SEC & "s"
    ClipPut($Info4)
    Beep(3500, 15)
EndFunc

Ah, well, the second way is not quite as good and hard to recycle this script, but what the heck. If it doesn't work, that's no good.

Tested. Working okay now. Thanks. :D

Link to comment
Share on other sites

The problem is that this line is evaluated on run-time:

$Info4 = @YEAR & "." & @MON & "." & @MDAY & "." & $ShortDayMyFormat & "; " & @HOUR & "h" & @MIN & "m" & @SEC & "s"
; The value of $Info4 here is no longer the entire line above, it is simply this: 2009.09.16.whatever; 8:59:32s
; That's because the line is evaluated only once, and it doesn't re-evaluate this every time. Unless you tell it to by repeating this line! Giving the programmer full control.

Image what would happen if a variable would be re-evaluated every time. What if I have this:

$Info = "Some data: " & _SelectFromDB("something")

ConsoleWrite($Info) ; This would call _SelectFromDB
ConsoleWrite($Info) ; This would call _SelectFromDB again! This now has deleted 6 rows in total. We didn't want this : (

Func _SelectFromDB("something")
   ; Deletes the first 3 rows from the database
   ; Select something
   ; Return the selected something
EndFunc

That's not very nice. 8)

Edited by Manadar
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...