DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

convert channel display format from time to numeric in a script

Solved!
Go to solution

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. 

0 Kudos
Message 1 of 5
(5,766 Views)

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

 

0 Kudos
Message 2 of 5
(5,750 Views)
Solution
Accepted by topic author steinmeister85
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.

0 Kudos
Message 3 of 5
(5,749 Views)

I was mistaking "displaytype" with "datatype" 🙂

0 Kudos
Message 4 of 5
(5,746 Views)

AndreasK,

 

That worked perfectly. Thanks for the tip of dragging properties into the script editor and thanks for your help.

0 Kudos
Message 5 of 5
(5,724 Views)