DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Using ChnCalculate with a variable

Solved!
Go to solution

The LIN/LIN_Error channel has 3000 values in it. I want to add a correction value to each of the 3000 values in it.

 

If I use a constant it works ok. For example:

Call ChnCalculate (" Ch(""LIN/LIN_Error"") =  ( 2 + Ch(""LIN/LIN_Error"" )   )" ) adds 2 to each value.

 

However if I try this with a variable it doesn't work.

 

Dim Corr

GlobalDim "Corr"

 

Corr  = 2
Call ChnCalculate (" Ch(""LIN/LIN_Error"") =  ( Corr + Ch(""LIN/LIN_Error"" )   )" )

0 Kudos
Message 1 of 3
(5,497 Views)
Solution
Accepted by topic author FrankHS

Hi Frank,

 

The problem is your first line.  By executing "Dim Corr" in the VBScript, you force that variable name to reference the VBScript variable and not the DIAdem global variable-- the color highlighting in the SCRIPT panel does not reflect this, which is confusing.  If you remove the Dim Corr statement, then the VBScript will correctly reference the global variable.  Another way of putting this is that your VBScript never sets the global Corr variable to 2.  The ChnCalculate() command correctly references the global Corr variable, but it is still set to 0.

 

However, for this task I would recommend instead the ChnLinScale() function, which is simpler, will execute faster, accepts regular VBScript variables, and therefore bypasses all of this confusion.

 

Dim Corr
Corr = 20
Call ChnLinScale("LIN/LIN_Error", "LIN/LIN_Error", 1, Corr)

Brad Turpin

DIAdem Product Support Engineer

National Instruments

Message 2 of 3
(5,483 Views)

This solved the problem. Both solutions worked and I went with your recommendation of ChnLinScale.

 

Thank you

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