Announcement

Collapse
No announcement yet.

Creating unique timestamp for filename, DatePart/Now() not updating between runs

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Creating unique timestamp for filename, DatePart/Now() not updating between runs

    Trying to deal with an image caching issue on Jowi's Random Picture script, I thought I might try doctoring the code of a script to make the target filename unique (ie. add a timestamp to the filename) and then dynamically update the hstouch element to load the updated image. HOWEVER, I've really never worked in vbscript before (I'm a beginner at best in perl and python).

    With some digging, I've been experimenting with DatePart, Hour, Minute, etc. Only I'm finding that the timestamp seems to be persisting between runs of the script. Here's a simple example:

    Code:
    Dim strDateTime = Now()
    hs.WriteLog("PictureRandom", "strDateTime is " & strDateTime)
    With the script running every 30 seconds, the resulting output in the log is:

    Code:
    Oct-10 10:42:40 PM         PictureRandom    strDateTime is 10/10/2018 10:41:40 PM
    Oct-10 10:42:40 PM         Event    Running script and waiting: C:/Program Files (x86)/HomeSeer HS3/scripts/JOWI_PictureRandomHallway1.vb
    Oct-10 10:42:40 PM         Event    Event Trigger "Hallway Rotate Hallway Screensaver"
    Oct-10 10:42:10 PM         PictureRandom    strDateTime is 10/10/2018 10:41:40 PM
    Oct-10 10:42:10 PM         Event    Running script and waiting: C:/Program Files (x86)/HomeSeer HS3/scripts/JOWI_PictureRandomHallway1.vb
    Oct-10 10:42:10 PM         Event    Event Trigger "Hallway Rotate Hallway Screensaver"
    Oct-10 10:41:40 PM         PictureRandom    strDateTime is 10/10/2018 10:41:40 PM
    Oct-10 10:41:40 PM         Event    Running script and waiting: C:/Program Files (x86)/HomeSeer HS3/scripts/JOWI_PictureRandomHallway1.vb
    Oct-10 10:41:40 PM         Event    Event Trigger "Hallway Rotate Hallway Screensaver"
    Notice that the first run shows the correct timestamp. However the two subsequent runs show the same timestamp. I'm at a lost as to how to resolve this. Once I resolve this I can reformat the stamp to something useful for the filename. Any suggestions?

    regards,

    Paul

    #2
    I just tried it with a vb.net script and it worked as expected.
    Code:
        Sub Main(ByVal Params As Object)
    
    
        Dim strDate as String = NOW
        hs.WriteLog("NOW", strDate)
    
        End Sub
    Mike____________________________________________________________ __________________
    HS3 Pro Edition 3.0.0.548, NUC i3

    HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

    Comment


      #3
      If you are just interested in a unique file name, you can also use the numerical value of the date.
      Code:
          Sub Main(ByVal Params As Object)
      
          Dim dblDate As Double = Now.toOADate
          hs.WriteLog("NOW", dblDate)
      
          End Sub
      yields this in the log
      Oct-13 5:20:13 PM NOW 43386.7223738079
      Mike____________________________________________________________ __________________
      HS3 Pro Edition 3.0.0.548, NUC i3

      HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

      Comment


        #4
        Yeah, I did put together a numerical date representation for the filename. The issue I was having was that (as seen from my above output, each time the script ran, it was still getting the date from the first run, rather than the current timestamp each run.

        As it turns out, my above example was flawed in that it didn't show how I executed the command out of context. I had the Dim line at the beginning of the script (before the Main sub), and then I had the writelog in the main sub. So what was happening was that the first run of the script would compile it in memory, and give a datestamp. But each subsequent run just ran the Main sub, and so wasn't getting a new timestamp. Once I figured that out, moved my dim statement into the Main sub, all worked as expected....

        Paul

        Comment

        Working...
        X