08-01-2014 08:26 AM
Hi all,
Simple question here. What is tha appropriate syntax for using a variable in a calculation equation. Specifically, I am taking an established curve fitting equation from my channels and trying to calculate it over a lineargenerated data set to extend the curve beyond the original data sample. Here is the small portion of script I have that will not work. Thanks for any help.
dim a,b,c
a = Data.Root.ChannelGroups(5).Channels("air consumption formula").Properties("ResultApprAnsatzCoef1").Value
b = Data.Root.ChannelGroups(5).Channels("air consumption formula").Properties("ResultApprAnsatzCoef2").Value
c = Data.Root.ChannelGroups(5).Channels("air consumption formula").Properties("ResultApprAnsatzCoef3").Value
Call Calculate("Ch(""[5]/Air Consumption LG"")= ""a"" + Ch(""[5]/LinearGenerated"")*""b""+""c""*ch(""[5]/LinearGenerated"")^2")
08-04-2014 10:47 AM
Hi crockengineer,
If you are using the calculator in DIAdem, it uses specific letters to determine the variable type. For example, if you want to have multiple variables of the type “LongInteger” you would use variables “L1”, “L2”, etc. This KnowledgeBase Article describes the various ways variables can be declared and used in DIAdem:
http://digital.ni.com/public.nsf/allkb/EB11ADBE70A4FDCD86256BF3005452BF
If you are using VBScript, you can use VBScript Variants which can be defined however you want. If the script uses the calculator, you will need to use the internal variables.
08-04-2014 11:37 AM
Hi Gloorious,
I am using diadem script. In my example above, for the equation, if I substitue a,b,and c with numerical values, the script runs just fine and the formula executes as desired. Is there a way to place the variables there instead as I have tried to do (I was hoping it was just a syntax issue) or do I have to approach it a completely different way?
This script will execute just fine:
Call Calculate("Ch(""[5]/Air Consumption LG"")= 4 + Ch(""[5]/LinearGenerated"")*5+6*ch(""[5]/L
but this will not:
dim a,b,c
a = Data.Root.ChannelGroups(5).Channels("air consumption formula").Properties("ResultApprAnsatzCoef1").Valu
b = Data.Root.ChannelGroups(5).Channels("air consumption formula").Properties("ResultApprAnsatzCoef2").Valu
c = Data.Root.ChannelGroups(5).Channels("air consumption formula").Properties("ResultApprAnsatzCoef3").Valu
Call Calculate("Ch(""[5]/Air Consumption LG"")= ""a"" + Ch(""[5]/LinearGenerated"")*""b""+""c""*ch(""[5]/L
08-05-2014 05:42 AM
I have ran into this issue before, Saw a post on the board from Andreas H of NI. Has worked out very well in practice.
Try making the calculation command a string, and then do a search and replace command to switch out the old Channel name with the new one. Then executing the command string. That will allow you to refer to different channels or properties as each iteration of script could require.
Paul
08-06-2014 05:28 PM
Hi crockengineer,
Here's another approach you can use to do this:
dim Channel
Set Channel = Data.Root.ChannelGroups(5).Channels("air consumption formula")
R1 = Channel.Properties("ResultApprAnsatzCoef1").Value
R2 = Channel.Properties("ResultApprAnsatzCoef2").Value
R3 = Channel.Properties("ResultApprAnsatzCoef3").Value
T1 = "[5]/LinearGenerated" Call Calculate("Ch(""[5]/Air Consumption LG"")= R1 + R2*Ch(T1) + R3*Ch(T1)^2")
Brad Turpin
DIAdem Product Support Engineer
National Instruments