From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Find all indices of a string in text channel

Solved!
Go to solution

I have text channels; each has some values containing the word "Shutdown". I would like to determine all the indices of those values. I tried ChnFind method but it was not successful. Please check the following code:

 

 

  for each oGrp in Data.Root.ChannelGroups
    ChnString = oGrp.Channels("Description").GetReference(eRefTypeNameName)
    Ind = 1
while Ind <> 0 Ind = ChnFind("Ch(ChnString)" & " contains " & """Shutdown""", Ind) wend next

PNo method can do the right job but it can only detect the first value.

I wonder if there is a method able to search string and support wildcards. It will be very helpful in this case. 

Thank you

0 Kudos
Message 1 of 4
(3,609 Views)

Hi,

 

I'm using Calculate function. In my case, when in one column (channel) string "0x36" occures, I copy from other column (channel) the corresponding value (which is located in the same row as required string), and create new channel with copied values, which only correspond to this found string. You can see example below:

 

Call Calculate("Ch(""[3]/Re0_P"")=IIf(Ch(""[1]/addr"")=""0x36"",Ch(""[1]/Re0_P""),NOVALUE)",NULL,NULL,"")

Ch(""[3]/Re0_P"") --> new channel with copied values

Ch(""[1]/addr"") --> channel with strings

Ch(""[1]/Re0_P"") --> channel with corresponding values

 

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

Hi,

Thank you for your idea. Using IIF is a good one.

However in my case, I want to detect the word "Shutdown" in all the string values of channel; this word is just a part of those interested string values. For example, I want to detect strings like:

"System_Shutdown"

"Engine_A_Shutdown"

"Temp_Shutdown"

"Shutdown_Ctrl"...

Direct comparison using "=" is not appropriate for my case.

0 Kudos
Message 3 of 4
(3,548 Views)
Solution
Accepted by topic author levan8421

I didn't have enough time to check it, but I found some discussions on StackOverflow about how to find substring in a string:

https://stackoverflow.com/questions/15585058/check-if-a-string-contains-another-string

https://stackoverflow.com/questions/2543225/how-to-get-a-particular-part-of-a-string

 

Maybe this will be helpful. I would be also interested how to do it in a smart and quick way. Maybe someone from DIAdem Support can answer this question.

In DIAdem you can search for InStr for VBS:

vInStr = Object.InStr(start, string, string2, [compare])
0 Kudos
Message 4 of 4
(3,529 Views)