1

The following code returns the error Invalid qualifier:

Set Nav_Selected = TL.ActiveBook.FindDataWatch("Navigator_SelectedOIDs")
Set Nav_Items = Nav_Selected.Data
Set block_path = Nav_Items.AttributeMap(0)
Set block_watch = TL.FindDataWatch(block_path)

Dim creationTime As Date
Dim localTime As String

'Get CreationTime
Set myWF = block_watch.Data
creationTime = myWF.Properties.Item("Created")
Set localTime = creationTime.ToLocalTime

I'm trying to get the localTime property from the creationTime object, just not sure how to do it. Thanks for the help.

Community
  • 1
  • 1
charwayne
  • 103
  • 1
  • 3
  • 18
  • 1
    What is the data type/format of "Created" data? – Jacob H May 16 '17 at 19:38
  • 1
    `creationTime` doesn't appear to be an `Object` type, either, since you didn't use the `Set` keyword on its assignment. – David Zemens May 16 '17 at 19:40
  • 1
    It's clear you've pulled this code from [this site](https://community.plm.automation.siemens.com/t5/Testing-Forum/LMS-Test-Lab-not-able-to-read-in-block-data/td-p/391430), but the code example there is not attempting to get `localTime`. Without any supporting documentation, it's hard to tell but my guess is that the `localTime` is not an object. So try `localTime = creationTime.ToLocalTime` without the `Set`. – PeterT May 16 '17 at 19:42
  • Is this VBA, or is this VB.Net? If it is VB.Net, none of the VBA suggestions will be of much use. (VBA doesn't treat `Date` types as objects, and they therefore don't have a `ToLocalTime` property.) – YowE3K May 16 '17 at 19:42
  • @PeterT impressed you found that. That was a question I asked when I first started this project but didn't realize the output time was in GMT. It was worked before adding localTime when creationTime was set to a string. I have tried using localTime without `Set` but without success. Unfortunately the documentation is thin and poorly written. – charwayne May 16 '17 at 19:59
  • @YowE3K it is in VBA – charwayne May 16 '17 at 19:59
  • 1
    In that case you can't treat the `Date` variable as a .Net `Date` object. **IF** `myWF.Properties.Item("Created")` is an object that supports a `ToLocalTime` method, you **may** be able to say `localTime = myWF.Properties.Item("Created").ToLocalTime`. – YowE3K May 16 '17 at 20:06
  • 1
    ... But judging by the webpage PeterT found, it looks like `myWF.Properties.Item("Created")` is just a `String`, so it won't have any useful properties or methods. – YowE3K May 16 '17 at 20:13
  • @YowE3K it at least compiles now! Thanks for the help, going to try and run it and see if I get useful results. – charwayne May 16 '17 at 20:14
  • @YowE3K well it appears you are right, no luck with running the compiled script – charwayne May 16 '17 at 20:19
  • 1
    I suggest you start reading [this question](http://stackoverflow.com/q/3120915/6535336) to get some tips on how to convert from UTC (I assume you have checked to make sure that "Created" isn't already in local time) to local time. – YowE3K May 16 '17 at 20:36
  • @YowE3K I appreciate the help, I've been testing it with no success – charwayne May 16 '17 at 20:45

1 Answers1

0

To solve this issue, I made changes following this article describing GMT and DLST corrections:

First, I added these functions to parse the string into a date object and then adjust for day light savings time (DLST) and Greenwich Median Time (GMT)

Function GetLocalTimeFromGMT(Optional GMTTime As Date) As Date
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' GetLocalTimeFromGMT
' This returns the Local Time from a GMT time. If GMTTime is present and
' greater than 0, it is assumed to be the GMT from which we will calculate
' Local Time. If GMTTime is 0 or omitted, it is assumed to be the GMT
' time.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim GMT As Date
Dim TZI As TIME_ZONE_INFORMATION
Dim DST As TIME_ZONE
Dim localTime As Date

DST = GetTimeZoneInformation(TZI)
localTime = GMTTime - TimeSerial(0, TZI.Bias, 0) + IIf(DST = 
TIME_ZONE_DAYLIGHT, TimeSerial(1, 0, 0), 0)
GetLocalTimeFromGMT = localTime

End Function
----------------------------------------------------------------------------
Function ParseDateTime(dt As String) As Date
  ParseDateTime = CDate(dt)
End Function

Next, I modified the the main function to call on the time adjustment functions:

'Get CreationTime
Set myWF = block_watch.Data
creationTime = myWF.Properties.Item("Created")
localTime = ParseDateTime(creationTime)

I now have time being fed into my function that is corrected for any time keeping methods and is accurate to within a few seconds.

Community
  • 1
  • 1
charwayne
  • 103
  • 1
  • 3
  • 18