11-09-2017 05:40 AM
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
Solved! Go to Solution.
11-09-2017 04:20 PM
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
01-08-2018 09:17 AM
Thanks Brad,
It works great!
01-09-2018 08:02 AM
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