LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to search an array?

Solved!
Go to solution

Hi to every1 going through this postSmiley Happy

 

I need your assistance in a prblm i am facing currently.

 

Description:

I enter a data when prompted. There is an array which is storing this data. I want to design a code such that the element entered checks with all the previous elements and sends an error if there is a repeatition or prompts to enter new data in case of no epeatition.

 

Can Search the 1-D array function or Match string functions can be used??If yes can you please explain.....If not then which is the fitting solution to this prblm????

 

Thanks a lot for reading this post. Awaiting your reply and solutions....and remarks!!!!!!!!

 

Regards,

Sushruth

0 Kudos
Message 1 of 12
(2,816 Views)

@KEMLab wrote:

 

Can Search the 1-D array function or Match string functions can be used??If yes can you please explain.....If not then which is the fitting solution to this prblm????

Yes, Search 1D Array can be used. Have you tried? Have you looked at the documentation before coming here and asking the question? It depends entirely on what your array contains. All you said is "data". Is it an array of strings? An array of integers? An array of floats? An array of clusters? Searching an array of floats using Search 1D Array is not likely to work due to the way floating point numbers are stored. If you don't understand what that means, then read this: math - Why can't decimal numbers be represented exactly in binary? - Stack Overflow

 

 

0 Kudos
Message 2 of 12
(2,813 Views)

Sorry for not writing details about the prolem...the data needs to be checked is string. I have tried using search 1-D array...But not able to execute it....

0 Kudos
Message 3 of 12
(2,802 Views)

Why are you not able to execute it? Do I look like a mind reader? Please provide details. What is your array of data? What are you searching for? Please post some code.

0 Kudos
Message 4 of 12
(2,798 Views)

I guess I have to accept your comment and sorry for not providing the details......I was thinking if there is a generic solution for this problem. Sorry once again...Below is the pic of the code and also have attached the code.error3.jpg

As you can see, I am able to display the URLs in the listbox. But am not able to check if there are any repetitions of the URLs as I dont know which function to use....Will upload the code with the functions I have used as soon as possible.....

0 Kudos
Message 5 of 12
(2,787 Views)

That VI does not even show you using a search 1-D array.

 

Show the VI where you used search 1-D array and is not working for you.

 

PS.  Sentences end with only 1 period.  No need to string together multiple periods to end your sentences.  It makes your message harder to read and looks like you are trailing off in your thoughts.

0 Kudos
Message 6 of 12
(2,780 Views)

I have attached the code....I am really not able to understand the output at the Search 1-D array.....I mean, I have given the array to besearched and the string to be searched....But what next????I am a beginner in Labview coding who is learning through mistakes like these, Sir. Hence please don't mind my silliness in the messages.....

0 Kudos
Message 7 of 12
(2,775 Views)
Solution
Accepted by topic author Sushkatta

Hi Sushruth,

 

You don't seem to be doing anything with the output of the Search 1D Array function. Are you planning to do anything else with this info?

 

 

The search function will give you the index number of the array element that contains your string. However as you have added this to the array in the same loop, the index number will always equal the for loop iteration number +1.

 

The URL should only be added to the array if it is not in there already. As the Search 1-D array function will return -1 if the URL isn't in the array, you could use a case structure to add the URL to the array in this case or return an error message if anything but -1 is outputted from the Search 1-D Array function.

 

CC 

 

p.s. Ctrl + h will bring up the context help, this will give you specific information of what each function (and its inputs) do.   

----------------------------------------------------------------------------------------------------------------------------
"If anyone needs me, I'll be in the Angry Dome!"


0 Kudos
Message 8 of 12
(2,759 Views)

Now you know the index of the array element if the item was found.  It it was not found, then the output is -1.  Do a boolean check on whether the output is < 0.  Use that to drive a case structure that does whatever you want in the case it is not found, and whatever else you want in case it is found.

 

You can actually eliminate the comparison and just wire the output directly to the case structure.  For a case -1, that is the not found case.  For a case of 0, default,  that is all other possibilities where the item was found.

 

Also, Insert into Array is the wrong function to use about 99% of the time when you are trying to build an array of data.  You should be using Build Array.

0 Kudos
Message 9 of 12
(2,757 Views)

Thanks a lot Guys. Now I have the idea on how to use the o/p of Search Array function. Though I used Ctrl+h for context help, I was not understanding what cane be done from the  o/p of Search Array function. Thanks for clarifying this doubt. Now I can develop my requirement on this. Once done will post the code.Pls have a look at it and suggest any modifications.

0 Kudos
Message 10 of 12
(2,750 Views)