DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Use of CreateTime - missing millseconds .....

Hi,

I use CreateTime to write a value to a property as follows: -

Call Data.Root.Properties.Add("Time", CreateTime(2016,6,17,10,20,10,5,0,0))

The value is written, but just partially.  The result is:-

06/17/2016 10:20:10

Anything smaller than seconds appears to be ignored, or else it is there and I am am not accessing it correctly. I use Diadem 2012.

Obviously, I am missing something. Any help is appreciated.

Thanks!

0 Kudos
Message 1 of 14
(3,997 Views)

If Value of an Property is accessed you get a variant CDate which by defaut only returns seconds.

The CreateTime generates a DIAdem time object that can hold the information.

 

Option Explicit

Call Data.Root.Properties.Add("Time", CreateTime(2016,6,17,10,20,10,5,100,0))
dim prop : set prop = Data.Root.Properties("Time")
MsgBox prop.oValue.Millisecond & " " & prop.oValue.MicroSecond & VBCRLF & prop.value

The object can be accessed by using oValue instead.

Hope this was already accessible in DIAdem 2012 but I think so.

 

0 Kudos
Message 2 of 14
(3,966 Views)

Hi mrme,

 

Your code looks good to me.  Try dragging that property from the Data Portal (drag the name, not the value) into the REPORT panel.  You should see a textbox with datetime precision down to the millisecond level, unless you've messed with the datetime display defaults.

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 3 of 14
(3,938 Views)

Hi Andreas,

Thanks for the response - it is somewhat clearer now.  Nevertheless, I have more questions which I will address to Brad (last post).

 

Thanks!

Thomas

0 Kudos
Message 4 of 14
(3,926 Views)

Hi Brad,

Yes, dragging the property into report works.  But something is not clear:-

(1) The properties in the data portal do not show the milliseconds.  Normal?

(2) Is there a way to capture all the date/time?  RootPropValGet does not grab the milliseconds.  The method of Andreas allows to grab the milliseconds alone.  I could use his method to rebuild the date/time by grabbing individually milliseconds, seconds, hours etc. and then reconstructing.  That seems a bit long winded and I suspect that I am still missing something...

 

Thanks!

Thomas

 

0 Kudos
Message 5 of 14
(3,924 Views)

Hi Thomas,

 

1) Yes this is normal.  It is also oversimplified and misleading, in my opinion, but you are not missing something.  That's the way DIAdem still is in version 2017.

 

2) What do you want to do with this information?  If you want to find the closest row that that datetime value in a datetime channel, then you actually don't want the datetime value at all, but rather the DIAdem Double representation.  If you really want a variant of subtype datetime that contains the full datetime accuracy, this is what you can do:

Set TimeObj = CreateTime(2017,1, 24, 13, 9, 30, 499, 0)
Data.Root.Properties.Add "NewTime", TimeObj
Set TimeObj = Data.Root.Properties("NewTime").oValue
VarTime = CDate(CDbl(TimeObj.VariantDate))
Data.Root.Properties.Add "CycleTime", VarTime

If you MsgBox VarTime you will only see accuracy down to the second in the display, but the variable contains the milliseconds.  By writing the variable back to another property and dragging that property onto the REPORT panel, you can verify that the milliseconds transferred and therefore were present in the variable.  So again, what do you want to do with that variable?

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 6 of 14
(3,907 Views)

Hi Brad,

 

I want to: -

(1) Convert dates from text format and write them in a Date channel.  This I can now do using split and CreateTime.

(2) Later on in the script, the milliseconds part of the date in the Time channel is used.  I need to grab just the milliseconds part as a separate variable.  This I cannot do.   The date displays correctly, but I am not able to use the method (.....

oValue.MilliSecond) successfully. In other words, I fail to assign the milliseconds part of the date to a variable.  Thanks again for the support.

 

TimeVals.PNG

Thomas

 

0 Kudos
Message 7 of 14
(3,884 Views)

If TimeVal is stored in channel it works equal.

Option Explicit

data.Root.Clear
dim chTime : set chTime = data.root.ChannelGroups.Add("group").Channels.Add("Time",DataTypeChnDate)
chTime.Values(1) = createTime(2017,6,6,10,23,45,200)
MsgBox chTime.oValues(1).Millisecond
0 Kudos
Message 8 of 14
(3,879 Views)

Hi Thomas,

 

We can convert the string channel to a datetime channel very efficiently using the Channel Calculator.  You can do the same thing to pull out the fractional component:

T1 = "##mm/dd/yyyy hh:nn:ss.ffff"
Set Group = Data.Root.ChannelGroups(1)
IF Group.Channels.Exists("DateTime") THEN Call Group.Channels.Remove("DateTime")
IF Group.Channels.Exists("TimeMsec") THEN Call Group.Channels.Remove("TimeMsec")
Set TimeChannel = Group.Channels("TimeVals")
Set DateChannel = Group.Channels.Add("DateTime", DataTypeChnDate)
Set MsecChannel = Group.Channels.Add("TimeMsec", DataTypeChnFloat64)
Call Calculate("DateCh = TTR(TimeCh, T1)", Array("TimeCh", "DateCh"), Array(TimeChannel, DateChannel))
Call Calculate("MsecCh = frac(DateCh)", Array("DateCh", "MsecCh"), Array(DateChannel, MsecChannel))

But this begs the question, "Wouldn't it be better to import your data like this automatically?".  What data file format are you loading, and what DataPlugin or other loading mechanism are you using to do so?

 

Also, what do you want to do with the variable that contains the milliseconds?  Is this a scalar variable, an array variable, or a channel variable?

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 9 of 14
(3,877 Views)

Hi Andreas,

I copied your example but get a strange result.  Is there also some format I should take care of ?  Some results: -

500 ms  gives 500 in the MsgBox.

200 ms gves 199 in the MsgBox

600 ms gives 500 in the MsgBox

 

My Time Format in settings is european (##dd/mm/yyyy hh:nn:ss.ffff)

 

Thank you

Thomas

 

Time_1.PNG

0 Kudos
Message 10 of 14
(3,865 Views)