DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

mathematical functions in Diadem

Can someone tell me how I simply add two channel properties together in Diadem VB script.
 
Or if I can calculate a new value by adding a variable to a channel property.
 
The output from the addition I would like to put back into a new Channel Property.
This code does not seem to work.
 
msgbox ChnPropValGet(1, "maximum") + ChnPropValGet(2, "maximum")
Thanks
0 Kudos
Message 1 of 5
(3,915 Views)
Hello Stagsden,
 
Could you provide some more information?  Such as what kind of error you received when you tried the [msgbox ChnPropValGet(1, "maximum") + ChnPropValGet(2, "maximum")] code?  This appeared to work for me when channels numbered 1 and 2 were numeric with updated characteristic values.
 
Julia
0 Kudos
Message 2 of 5
(3,905 Views)

Hello Julia,

 

First of all the command ChnPropvalGet does not seem to be recognised by Diadem. I am using version 10.0

msgbox ChnPropValGet("[1]/EnergyAKJ", "maximum") + ChnPropValGet("[1]/EnergyBKJ", "maximum")

The values which I want to add our Real values.

 

Also this statement puts the Total into a msgbox, can I put it into a property value.

Thanks

 

Stagsden.

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

You are correct - it looks like ChnPropValGet only shows up in DIAdem 10.1.  I use different versions of DIAdem, so often re-create the new functions that I enjoy and register them as a user command (using ScriptCmdAdd).  I think something like the function below should give you somewhat similar results.  And yes, you should be able to put this value into a channel property by using the ChnPropSet command, and perhaps the ChnPropCreate command, if you want to create a new property.  For example, the bit between the dashed lines saves the sum of the maximum values to the variable, "MaxSumVal" and then creates a property for channel #5 called "MaxSum" and sets this value to MaxSumVal.  But you could also put the value in an already-created property, but some excisting channel properties are read-only.  I hope this is not confusing!

--------------
MaxSumVal = ChnPropValGet(4, "maximum") + ChnPropValGet(3, "maximum")
Call ChnPropCreate(5, "MaxSum", DataTypeFloat64)
Call ChnPropSet(5, "MaxSum", MaxSumVal)
Call ChnPropSet(5, "Description", MaxSumVal)

--------------

Public Function ChnPropValGet(ChnNum, ChnProperty)
  Dim ChanType
  ChanType = ChnPropGet(ChnNum, "displaytype")
  Select Case ChanType
    Case "Numeric"  ChnPropValGet = Val(ChnPropGet(ChnNum, ChnProperty))
    Case "Text"     ChnPropValGet = ChnPropGet(ChnNum, ChnProperty)
    Case "Time"     ChnPropValGet = ChnPropGet(ChnNum, ChnProperty)
    Case Else       ChnPropValGet = ""
  End Select
End Function ' ChnPropValGet

 

0 Kudos
Message 4 of 5
(3,898 Views)
Thank you very much Julia for the quick responce.
0 Kudos
Message 5 of 5
(3,895 Views)