08-12-2020 06:21 AM
I have created a VI that creates 1d array of strings of available VISA resources. I can separate these with index selector but the problem is that VISA resource could possibly be at any index location. Can I choose certain index that starts with certain pre-defined text?
For example if I have 2 index and index I want to choose starts with "USB.." and other(s) does not, how can I allways choose the one that starts with "USB.."
Solved! Go to Solution.
08-12-2020 06:27 AM
Use a FOR loop to iterate through your strings and stop the loop early when you find an element that matches your criteria. Or if you are just using an exact string match use Search 1D Array.
08-12-2020 06:44 AM
What function should I use to find correct index when using FOR loop? It is not an exact match so Search 1D Array is no good. I didn't find anything suitable for comparison functions also?
08-12-2020 06:59 AM
Hi LWnew,
@LWnew wrote:
What function should I use to find correct index when using FOR loop?
Did you note this little "i" item inside the loop, which tells you the number of the current iteration?
@LWnew wrote:
I didn't find anything suitable for comparison functions also?
When you want to parse strings then you should use a string function. MatchPattern might work for you…
08-12-2020 07:13 AM
Hi,
Here is an example for my current found VISA resources.
Program has found 2 VISA resources. I want to choose full USB one, but the problem is that it could be in any index. Match pattern divided my string in 3 parts. If I use USB as regular expression it divides USB to "match substring"
Here is also the program that I use for testing this.
08-12-2020 07:14 AM
@LWnew wrote:
What function should I use to find correct index when using FOR loop?
Do you care about the index or just the actual value? If you just want the index, then wire the i out of the loop. If you really just want the value, then wire the value out of the loop (do not index the output tunnel and you will get the last value).
08-12-2020 07:25 AM - edited 08-12-2020 07:25 AM
@LWnew wrote:
Program has found 2 VISA resources. I want to choose full USB one, but the problem is that it could be in any index. Match pattern divided my string in 3 parts. If I use USB as regular expression it divides USB to "match substring"
Give this a try.
08-12-2020 08:33 AM
@crossrulz wrote:
@LWnew wrote:
Program has found 2 VISA resources. I want to choose full USB one, but the problem is that it could be in any index. Match pattern divided my string in 3 parts. If I use USB as regular expression it divides USB to "match substring"
Give this a try.
Same as above (Except using a conditional terminal on the for loop)
08-12-2020 08:56 AM
Both seem to be working. Thanks all.
08-12-2020 09:04 AM
@adekruif wrote:Same as above (Except using a conditional terminal on the for loop)
Good call! I will state that is is not uncommon for me to pass the conditional value out so I can generate an error if the element was not found. You just fixed an old habit of mine (I've been doing these types of searches since the conditional terminal was added to the FOR loop in LabVIEW 8.6, the tunnel conditional was added much later).