DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Looping through channels and groups in VB

I am trying to setup a format to loop through groups and run an identical function on the channels, where the channel names are the same. I cannot find an easy format to perform this under. Here is the example code I am trying to get to work:

dim intMyChnla, intMyChnlb, intMyChnlc, intMyChnld
dim indexgroup, sGrpName

for indexgroup=1 To GroupCount ' step 1

sGrpName = GroupName(indexgroup)
intMyChnla = CNo("sGrpName/ABCAhIn")
intMyChnlb = CNo("sGrpName/Total_ABCAhIn")
intMyChnlc = CNo("sGrpName/ABCAhOut")
intMyChnld = CNo("sGrpName/Total_ABCAhOut")

Call FormulaCalc ("Ch('sGrpName/Calc_Total_AH_Throughput') := Ch('sGrpName/intMyChnla') + Ch('sGrpName/intMyChnlb') + Abs(Ch('sGrpName/intMyChnlc')) +Abs(Ch('sGrpName'/intMyChnla'))")


the following calculation works in the Calculator, but I have to change the 20 number to correspond to the Group.
Ch('[20]/Calc_TotalAhThroughput'):= Ch('[20]/ABCAhIn') + Ch('[20]/Total_ABCAhIn') + Abs(Ch('[20]/ABCAhOut')) +Abs(Ch('[20]/Total_ABCAhOut'))


Thanks for the help.
Rich
0 Kudos
Message 1 of 3
(4,265 Views)
Hello Rich,

I think I understand why it doesn't work as expected : In your call to Formulacalc you write

Call FormulaCalc ("Ch('sGrpName/Calc_Total_AH_Throughput') := Ch('sGrpName/intMyChnla') + Ch('sGrpName/intMyChnlb') + Abs(Ch('sGrpName/intMyChnlc')) +Abs(Ch('sGrpName'/intMyChnla'))")

You have set the local VBS variable sGrpName to the groupname. But within the call to Formulacal its a simple text. With that DIAdem tries to find a group named "sGrpName" which probably doesn't exist. You could write something like :

sGrpName = GroupName(indexgroup)
sgCommand = "Ch('#1/Calc_Total_AH_Throughput') := Ch('#1/intMyChnla') + Ch('#1/intMyChnlb') + Abs(Ch('#1/intMyChnlc')) +Abs(Ch('#1/intMyChnla'))"
sgCommand = Replace(sgCommand,"#1",sGrpName)
Call FormulaCalc (sgCommand)

The Replace function will replace the text "#1" with the group name stored in your local variable sGrpName. You may want to check sgCommand to see whether everything works right.

Andreas
0 Kudos
Message 2 of 3
(4,260 Views)
Yes, that essentially worked for me.  Thank you.

Here is what the final script looks like:
dim intMyChnla, intMyChnlb, intMyChnlc, intMyChnld
dim indexgroup, sGrpName, sgCommand

for indexgroup=1 To GroupCount ' step 1

intMyChnla = CNo("ABCAhIn")
intMyChnlb = CNo("Total_ABCAhIn")
intMyChnlc = CNo("ABCAhOut")
intMyChnld = CNo("Total_ABCAhOut")

' Call FormulaCalc ("Ch('sGrpName/Calc_Total_AH_Throughput') := Ch('sGrpName/ABCAhIn') + Ch('sGrpName/Total_ABCAhIn') + Abs(Ch('sGrpName/ABCAhOut')) +Abs(Ch('sGrpName'/Total_ABCAhOut'))")


sGrpName = GroupName(indexgroup)
sgCommand = "Ch('#1/Calc_Total_AH_Throughput') := Ch('#1/ABCAhIn') + Ch('#1/Total_ABCAhIn') + Abs(Ch('#1/ABCAhOut')) +Abs(Ch('#1/Total_ABCAhOut'))"
sgCommand = Replace(sgCommand,"#1",sGrpName)
Call FormulaCalc (sgCommand)

Next

0 Kudos
Message 3 of 3
(4,242 Views)