DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Count occurrence of text in channel

Solved!
Go to solution

Hi,

I have got channel with "OK" and "NOK" text depending on values from other channels. I would like to count how many "OK" and "NOK" are in that channel but could not find anywhere how to do that.

Would anyone be able to help?

 

Thanks

Jan

0 Kudos
Message 1 of 4
(2,593 Views)
Solution
Accepted by topic author JanSantora

Hi Jan,

 

Here's code that does what you describe as efficiently as possible.  You could instead loop through each string channel value and compare it manually with VBScript, but that would run much slower.  The Assignment channel is the easiest way to count the number of distinct string values to loop through.  If you have an old version of DIAdem, you'll have to provide the string states manually in a constant array.

 

Note that the TDM file is sufficient without a TDX file because the only data channel is a string channel.

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

Download All
0 Kudos
Message 2 of 4
(2,571 Views)

Thanks Brad,

 

It works great!

0 Kudos
Message 3 of 4
(2,509 Views)

Hi All,

 

My boss just pointed out to me that if you have DIAdem 2017 or later, you can use the "ChnEventDetectionEqualStr()" function to vastly simplify the code.  DIAdem 2017 also has a "ChnEventDetectionInStr()" function for partial string comparisons.

 

Set Group = Data.Root.ChannelGroups(1)
Set Channel = Group.Channels(1)
Events = ChnEventDetectionEqualStr(, Channel, "NOK")
NotOkCount = ChnEventSampleCount(Events)
OkCount = Channel.Size - NotOkCount
MsgBox "OK = " & OkCount & vbCRLF & "Not OK = " & NotOkCount

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 4 of 4
(2,499 Views)