DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

delete a group if any channel contains a novalue script

Hey everybody,

I am attempting to add to my script the scenario described in this message title: Delete a group if any channel contains a novalue.  I have tried the following script but it doesn't seem to do anything at all when I am  using a data set with a group that I know has a channel called temp with novalue as the minimum.


dim i
for i=1 to data.Root.ChannelGroups.Count
if Data.Root.ChannelGroups(i).Channels("temp").Properties("minimum").Value = Nv then
Call Data.Root.ChannelGroups.Remove(i)
else Data.Root.ChannelGroups(i).Channels("temp").Values(1)=Data.Root.ChannelGroups(i).Channels("temp").Values(1)
end if
next

if I run this script, the group with a novalue "temp" channel still remains.  Thanks for any help.

0 Kudos
Message 1 of 5
(5,342 Views)

Hi crockengineer,

 

it is helpful to calculate the channel characteristic values first and then to check a property which tells you whether a channel contains NoValues or not. Here is an example:

 

dim iLoopG, iLoopC, oGroups, oGroupChns, bDelGroup

Call ChnCharacterAll ' calculate all channel characteristic properties

set oGroups = Data.Root.ChannelGroups
iLoopG = 1
do while iLoopG < oGroups.Count
  bDelGroup = false
  set oGroupChns = oGroups(iLoopG).Channels
  for iLoopC = 1 to oGroupChns.Count
    if oGroupChns(iLoopC).Properties("novaluekey").Value = "Yes" then 
      bDelGroup = true
      exit for
    end if
  next
  if bDelGroup then 
    oGroups.Remove(iLoopG)
  end if
  iLoopG = iLoopG + 1
loop

 

Greetings

Walter

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

Thanks Walter_Rick.

I was able to make this work partially.  However, if two groups that contain a novalue channel are one right after the other (say group 3 and 4), then this script will delete the group 3 but not the group 4 since group 4 becomes group 3 when the first novalue group is deleted.  To solve this I added the following after the last endif:

if bDelGroup then
iLoopG = iLoopG
else
iLoopG = iLoopG + 1
end if
loop

 

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

You're right and if the last group contains a NV it was also not deleted. Here is a new version:

 

dim iLoopG, iLoopC, oGroups, oGroupChns, bDelGroup

Call ChnCharacterAll ' calculate all channel characteristic properties

set oGroups = Data.Root.ChannelGroups
iLoopG = 1
do while iLoopG <= oGroups.Count
  bDelGroup = false
  set oGroupChns = oGroups(iLoopG).Channels
  for iLoopC = 1 to oGroupChns.Count
    if oGroupChns(iLoopC).Properties("novaluekey").Value = "Yes" then 
      bDelGroup = true
      exit for
    end if
  next
  if bDelGroup then 
    oGroups.Remove(iLoopG)
    iLoopG = iLoopG - 1
  end if
  iLoopG = iLoopG + 1
loop

 

Greetings

Walter

 

0 Kudos
Message 4 of 5
(5,285 Views)

In the case where I'm deleting items from an array (or in your case a channelgroup) so that shifting happens, I find looping starting at the end and working toward the beginning to be the simplest method. This eliminates any problem with shifting.

0 Kudos
Message 5 of 5
(5,272 Views)