DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Conditional formula not working?

Hi,

 

I've updated some 2010 code to 2019 and (at least) one particular line is failing. The old code is:

 

  Call FormulaCalc("Ch('FRF phase'):=Ch('FRF phase') - (Ch('FRF re')>0.0 And Ch('FRF im')<0.0) * (2.0 * Ch('FRF phase'))")

 

And the updated version is:

 

  Call Calculate("Ch(""FRF phase"") = Ch(""FRF phase"") - (Ch(""FRF re"")>0.0 And Ch(""FRF im"")<0.0) * (2.0 * Ch(""FRF phase""))")

 

I know that the input channels, 'FRF re' and 'FRF im' are the same in both cases. The And operation seems to identify the right sections of the channels, but the later line of code adds the rightmost part of the equation to 'FRF phase' rather than subtracting it.

 

Is there something about the way formulas are laid out in 2019 that I don't know about?

 

Regards,

 

Simon.

0 Kudos
Message 1 of 5
(2,442 Views)

By way of some additional information, the following code returns -1 when true (and 0 when false):

  Call Calculate("Ch(""FRF phase"") = Ch(""FRF re"")>0.0")

Naturally, I'm expecting it to return 1, as it did in the old code! Anyone know what's happening here?

 

Regards. 

0 Kudos
Message 2 of 5
(2,417 Views)

Some general information:

Since several years we recommend working with the Data-API and with that with channel objects. Then calculate command can look like this:

 

Dim sFormula, aSymbol(2), aValues(2)

sFormula = "Ch(""Result"") = A / B"

aSymbol(1) = "A"

aSymbol(2) = "B"

Set aValues(1) = Data.GetChannel("[1]/[2]")

Set aValues(2) = Data.GetChannel("[1]/[3]")

Call Calculate (sFormula, aSymbol, aValues)

Or if is only a part of your script it could be that:

dim oChnY, oChnA, oChnB

Dim sFormula, aSymbol(3), aValues(3)

 

set oChnA = Data.GetChannel("[1]/[2]")

set oChnB = Data.GetChannel("[1]/[3]")

 

' ... do something with these channels

 

set oChnY = Data.Root.ChannelGroups(1).Channels.Add("My_Y_Chn", DataTypeChnFloat64)

 

sFormula = "Y = A / B"

aSymbol(1) = "Y"

aSymbol(2) = "A"

aSymbol(3) = "B"

Set aValues(1) = oChnY

Set aValues(2) = oChnA

Set aValues(3) = oChnB

Call Calculate (sFormula, aSymbol, aValues)

 

' ... do more ...

 

In VBS is the return value for TRUE -1.

 

Greetings

Walter

0 Kudos
Message 3 of 5
(2,374 Views)

Thanks Walter. Yes, I appreciate my code is old fashioned but it's usually quicker to make small adjustments to the old code than re-write it completely. My experience of using the new language is that it is frequently longer (more lines for the same output) and this somewhat offsets any benefit in flexibility or power it might bring - at least at my level of writing.

 

I have contacted NI to suggest they update their help files so that they clearly state that TRUE = -1 and not 1!

 

Thanks.

0 Kudos
Message 4 of 5
(2,370 Views)

Yes, script code maybe a bit longer but it gives you the option to better structure it and with that having an eraser readable code for maintaining.

One of the reasons for developing the new API’s in DIAdem is performance. For example, if you work with a channel object like:

 

Set oChn = Data.Root.ChannelGroups(x).Channels(y)

 

the access to a certain value is about 100 times faster than with CHD().

 

But in the end you are right, small adjustments are quicker and it depends on performance and on how often you change your script to decide whether it is helpful to change the whole script and save time long term wise.

 

Greetings

Walter

0 Kudos
Message 5 of 5
(2,365 Views)