10-31-2013 04:59 AM
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
Solved! Go to Solution.
10-31-2013 08:51 AM
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,
10-31-2013 09:24 AM
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
10-31-2013 10:36 AM - edited 10-31-2013 10:38 AM
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.
10-31-2013 10:42 AM
Here is an example showing both.
10-31-2013 11:31 AM
Thanks for your help Jigg,
That got it done!
02-26-2019 01:26 AM
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"
I don't understand what this is for "String Did Not Contain Connected"
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
02-26-2019 11:01 AM
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,
03-04-2019 07:19 AM
Thanks jigg:)