LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Comparing input to information in a .csv file using Read from Spreadsheet

Solved!
Go to solution

I need to compare each row of a spreadsheet to input from the user. I can read from the spreadsheet fine, but I am having trouble comparing one row at a time. I know I need to somehow compare each row using a loop, then OR all the results, but I can't seem to figure it out.


Attached is what I have so far.

 

The cluster with John Smith was used to test the compare.

 

 

 

 

0 Kudos
Message 1 of 11
(5,634 Views)

I'm at home right now so I can't look at your code, but unless it is absolutely unavoidable never process an array one element at a time.

 

Consequently, comparing one row at a time is the absolute worst way of doing what you describe. There are a number of good ways to accomplish what you want. For example, there's a built-in function that searches 1D arrays for a given input and returns -1 if its not found.

 

You could also do a simple equality comparison between an array of values and a scalar input. The result would be an array of booleans, if any of the bits are true, you've found your answer. The first technique is generally more efficient, but the second one has its place too. Say for example you want to know how many elements equal the input, or you want to find the values exceeding some value.

 

Can you post a screen shot of your code?

 

Mike...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 2 of 11
(5,624 Views)

You only need a WHILE loop for the comparison.

Once the user's input and the entry from the row from the spreadsheet do not agree, you don't need to compare anymore.

0 Kudos
Message 3 of 11
(5,620 Views)

Thank you for the timely reply.

 

Here is a screen shot.proj1ss.png

 

It's really basic at the moment. I haven't gotten very far with reading from the spreadsheet, ha.

 

Could you elaborate on the first method you mentioned?

 

0 Kudos
Message 4 of 11
(5,608 Views)

Okay, I got something working, but like you said, it doesn't seem like the best way.

 

proj1ss.png

0 Kudos
Message 5 of 11
(5,592 Views)

 The code in this screen shot is one approach but there is some optimization that you can do. I'm assuming that the data in the file is written such that you have a column of names, a column of user ids and a column of pins. Using the spreadsheet read VI like you are using you get a 2D array of strings where each row is one user.

 

The first thing is to decide what column you want to do your initial search on. I would recommend User ID since you can enforce a requirement that it be unique. So using an array index node, index column 1 from the data you got from the file. To get an entire column, wire a constant to the column selector and leave the row unwired. The results is a 1D array of all the user ids.

 

Now use a search 1d array node to search the array for the user ID the user entered. If the result of that search is -1, the search was unsuccessful so you don't need to look any further. If the result is anything else its the row where the user ID was found.

 

Now all you have to do is use another array index function but this time wire a contant with the value 2 to the column selector and the value you got from the search function to the row selector. The result is the pin associated with the user ID. All you have to do now is compare it to the pin that the user entered. If they match the login was good.

 

Mike...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
Message 6 of 11
(5,571 Views)
Solution
Accepted by topic author steezeburger

What exactly is your goal here?  Do you just want to know if you got a match?  Or do you want to know which row matches?

This last solution you have will cause an endless loop if you can't find a match.  Use a FOR loop instead.  Here's the code I would use.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 7 of 11
(5,566 Views)

@Mike:

 

Would this be much more efficient than what I was originally thinking? Why is evaluating one element at a time a bad idea? I'm trying to learn the best practice for everything. I really appreciate all your help by the way.

0 Kudos
Message 8 of 11
(5,551 Views)

this would work, but there is one very large problem: scalability.

 

If you have 50 users this might work well, but what if you have 5000 or 50,000. Now you have to go through 50000 records to determine that the record you're looking for doesn't exist.

 

By contrast, the solution I described scales very well.

 

Mike...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 9 of 11
(5,546 Views)

I figured this was the issue. Thank you very much!

0 Kudos
Message 10 of 11
(5,541 Views)