09-13-2012 02:35 PM
Hey guys,
I'm new to working with Diadem Scripts. I have tried the two different ways below to make the values of a channel equal to the results of a formula containing created variables. I can do it if the formula contains values in place of the variables using the calculator method. I would appreciate any guidance on how to correct the syntax in the below scripts.
Option Explicit 'Forces the explicit declaration of all the variables in a script.
dim a, b, c
a = Data.Root.ChannelGroups(2).Channels("rop regression formula").Properties("ResultNonLinearFitCoef1").Value
b = Data.Root.ChannelGroups(2).Channels("rop regression formula").Properties("ResultNonLinearFitCoef2").Value
c = Data.Root.ChannelGroups(2).Channels("rop regression formula").Properties("ResultNonLinearFitCoef3").Value
Ch ("[2]/ROP (ft/hr)") = a + b* Ch("[2]/Backhead Pressure (psi)") + c* Ch("[2]/Backhead Pressure (psi)")^2
Or
Option Explicit 'Forces the explicit declaration of all the variables in a script.
dim a, b, c
a = Data.Root.ChannelGroups(2).Channels("rop regression formula").Properties("ResultNonLinearFitCoef1").Value
b = Data.Root.ChannelGroups(2).Channels("rop regression formula").Properties("ResultNonLinearFitCoef2").Value
c = Data.Root.ChannelGroups(2).Channels("rop regression formula").Properties("ResultNonLinearFitCoef3").Value
call ChnCalculate("Ch(""[2]/ROP (ft/hr)"")="&a+&b"*Ch(""[2]/Backhead Pressure (psi)"")+"&c"*Ch(""[2]/Backhead Pressure (psi)"")^2")
09-13-2012 04:33 PM
I think you need to use channel name strings of the format "Group Name/Channel Name" in your ChnCalculate function. I usually use a formula, a symbol array, and a value array to get this done:
Dim a, b ,c, sFormula, aSymbols, aValues
Redim aSymbols(6), aValues(6)
aSymbols(0) = "a"
aSymbols(1) = "b"
aSymbols(2) = "c"
aSymbols(3) = "A"
aSymbols(4) = "B"
aValues(0) = Data.Root.ChannelGroups(2).Channels("rop regression formula").Properties("ResultNonLinearFitCoef1").Va
lue
aValues(1) = Data.Root.ChannelGroups(2).Channels("rop regression formula").Properties("ResultNonLinearFitCoef2").Value
aValues(2) = Data.Root.ChannelGroups(2).Channels("rop regression formula").Properties("ResultNonLinearFitCoef3").Value
aValues(3) = Data.Root.ChannelGroiups(2).Channels("ROP (ft/hr)").GetReference('ref type')
aValues(4) = Data.Root.ChannelGroiups(2).Channels("Backhead Pressure (psi)").GetReference('ref type')
sFormula = "Ch(A) = a + b*Ch(B) + c*(Ch(B))^2"
Call ChnCalculate(sFormula,aSymbols,aValues)