09-30-2014 04:39 PM
I am trying to convert the Display format of a channel that contains time values (mm/dd/yyyy hh:nn:ss.ffff) from Time to Numeric. I know I can do this in the properties section of the data portal but I would like to do it in a script. I want to be able to automatically convert it without having to manually do it each time I import new data. What syntax is needed for this?
I've already tried the ChnPropSet (and ChnPropValSet) commands but it doesn't change the Display format after I run the script. Thanks for all your help.
Solved! Go to Solution.
10-01-2014 02:55 AM
Hi Steinmeister,
i've found a way. You can use the "ChnCalculate"-Function but you must store it to a new channel.
Dim oGrp, oChn Dim sChn 'iterate over all channels For Each oGrp In Data.Root.ChannelGroups For Each oChn In oGrp.Channels sChn = transformTimeChnToNum(oChn) If (sChn <> "") Then Call ChnCopy(oGrp.Name & "/" & sChn, oGrp.Name & "/" & oChn.Name) Call ChnDel(oGrp.Name & "/" & sChn) End If Next Next 'function for transforming the channel Function transformTimeChnToNum(oChannel) transformTimeChnToNum = "" If (oChannel.DataType <> DataTypeChnDate) Then Exit Function End If transformTimeChnToNum = oChannel.Name & "_num" Call ChnCalculate("Ch(""" & oChannel.ChannelGroup.Name & "/" & transformTimeChnToNum & """)=Val(Ch(""" & oChannel.ChannelGroup.Name & "/" & oChannel.Name & """))") End Function
10-01-2014 03:01 AM
Data.Root.ChannelGroups(1).Channels("Zeit").Properties("displaytype").Value = "time" Data.Root.ChannelGroups(1).Channels("Zeit").Properties("displaytype").Value = "numeric"
For me the two lines switch the type. Be aware that the property is "displaytype" not the localized GUI name.
You can determine the name of a property by drag and drop it into the DIAdem script editor.
10-01-2014 03:06 AM
I was mistaking "displaytype" with "datatype" 🙂
10-01-2014 03:15 PM
AndreasK,
That worked perfectly. Thanks for the tip of dragging properties into the script editor and thanks for your help.