NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use String Function Find() in a String Value Test?

Solved!
Go to solution

Hi,

i intend to match a substring of the string returned from my UUT when using a String Value Test - VI call.

I write the returned string to a Local Variable type String (Locals.data_read) and in the Limits Tab - under Expected String Value am using Find(Locals.data_read, "Connected"). When i Check the expression for Errors - i get a warning "Expected String, found Number {64-bit Floating Point}. this value will cause a run-time error."

 

What am i missing?

Thanks

Kech

 

0 Kudos
Message 1 of 9
(15,370 Views)

The Find function evaluates to a number:

 

Number Find(String string, String stringToSearchFor, Number indexToSearchFrom = 0, Boolean ignoreCase = False, Boolean searchInReverse = False)

 

Returns: The zero-based character index, starting at the beginning of the string, of the first character in the substring.  The function returns -1 if it does not find the substring.

 

 

 

It looks to me like you need to do a numeric step type.  Not a string value test.

 

Or you can do something like this:

 

Find(Locals.data_read, "Connected") < 0 ? "Doesn't Matter What Is Here" : Locals.data_read

 

Hope this helps,

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
Message 2 of 9
(15,362 Views)

Hi Jigg,

 

 

sorry - i'm not getting it...

Using <<Find(Locals.data_read, "Connected") < 0 ? "Doesn't Matter What Is Here" : Locals.data_read>> in the String Value Test didn't work.

 

And if i use a Numeric step type - under Limits-> Comparison Type - the expression Find(Locals.data_read, "Connected") is not accepted ?

 

cheers

Kech

0 Kudos
Message 3 of 9
(15,357 Views)

You need to change your Data Source to Locals.data_read for the string value test.

 

You need to change your Data Source on the Numeric Limit Test to your Find Function.

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 4 of 9
(15,349 Views)
Solution
Accepted by topic author kech

Here is an example showing both.

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
Message 5 of 9
(15,345 Views)

Thanks for your help Jigg,

 

That got it done!

 

0 Kudos
Message 6 of 9
(15,339 Views)

Hi

I know this is an old thread but I have a question about this solution.

 

I the attached sequence this "Find(Locals.data_read, "Connected") < 0 ? "String Did Not Contain Connected"" : Locals.data_read" is stated in limits for step "Evaluate string"

I don't understand what  this is for "String Did Not Contain Connected"" : Locals.data_read", because no matter what the text you are validating, this text will not show in Locals.data_read, if Connected is not pressent. The text that will be in the variable is the text you type in step "Get string".

 

Another question is. How can i set it up to find more than one text?

I need it to find out if one of 3 differeret sentence or words is pressent in the stream from a RS232 port and save the one that is pressent in a variable. I need this to chose what to do next in the sequence.

 

Hope someone can help.
Thanks in advance:)

 

Best regards Bjarne

 

0 Kudos
Message 7 of 9
(9,037 Views)

I would recommend starting a new thread and referencing this one in the future.  That will help keep each issue independent to make searching easier.


@Briton wrote:

Hi

I know this is an old thread but I have a question about this solution.

 

I the attached sequence this "Find(Locals.data_read, "Connected") < 0 ? "String Did Not Contain Connected"" : Locals.data_read" is stated in limits for step "Evaluate string"

I don't understand what  this is for "String Did Not Contain Connected"" : Locals.data_read", because no matter what the text you are validating, this text will not show in Locals.data_read, if Connected is not pressent. The text that will be in the variable is the text you type in step "Get string".

The Data Source is Locals.data_read.  If the data read contains the word "Connected" then it is a pass for the step because the Expected String Value will evaluate to the same thing as the Data Source.  This is how the String Value Test Step Type Works.  You can see this in the Status Expression.  The actual reading will always show on the report because it is the Data Source.

 


@Briton wrote:

 

Another question is. How can i set it up to find more than one text?

I need it to find out if one of 3 differeret sentence or words is pressent in the stream from a RS232 port and save the one that is pressent in a variable. I need this to chose what to do next in the sequence.


You could use nested conditional statements but that could get out of hand quickly if you go beyond a few of these statements. 

Find(Locals.data_read, "String1") < 0 ? (Find(Locals.data_read, "String2") < 0 ? (Find(Locals.data_read, "String3") < 0 ? "String Did Not Contain Connected" : Locals.data_read): Locals.data_read) : Locals.data_read

 

As for chosing what to do next in the sequence what are your options?  You can use the Post Action, an engine callback or many different ways to go from here.

 

Cheers,

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
Message 8 of 9
(9,021 Views)

Thanks jigg:)

0 Kudos
Message 9 of 9
(8,957 Views)