LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Use an array to count instances in another

Solved!
Go to solution

Ok, so I'm a very new person to Labview but understand the layout/coding if it is explained properly. I'm having a problem understand what I need to do next in my small program. 

 

What I am doing is reading 2 files. 1 file shows Model names of computers, and I have that into a 1D array. The second file is a compiliation of Received computers in a day (Incoming Shipments). So far with the second file, I have that into a Spreadsheet string to array with "%s" Format string, "-" Delimiter and 2D Dbl array type. Output of Spreadsheet string to array goes into an Index Array with an Index colum of "1". Everything is pulling the information that I need/want. 

What I want to do is compare the set Model Names from the 1st file and count how many of each model arrived through the second file.

 

EX

Total Received: 106

X Model: 40

D Model: 35

C Model: 31

 

I'm stuck on how to do the next step. I've tried searching for examples, but none are helping enough to jog my brain. Any help would be appreciated.

0 Kudos
Message 1 of 11
(3,587 Views)

 

You are missing the sub-vi you call in "Project 1.vi".  Also, we can help you better if you give us sample .txt files you are reading in (or just copy/paste some of the lines) so we have an idea of what you are trying to do.

 

That having been said, I'd look in to storing your data in an array of clusters.  Each cluster has a string for the model and a numeric for the quantity.  For every computer in your second file just search the array for the correct model and increment the quantity accordingly.

0 Kudos
Message 2 of 11
(3,576 Views)

I had to make some assumptions about your data, but this should work.

 

Count Received.png

0 Kudos
Message 3 of 11
(3,561 Views)
Solution
Accepted by Redreghan

As far as couting the different models, Variant Attributes work extremely well.


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 4 of 11
(3,537 Views)

Sorry, didn't realize I was using a Subvi, I changed it to not have the Subvi and used the original code. Re-uploaded VI.

 

As far as the data, here is what I have:

Models.txt has 15 Models total:

 

Model A

Model B

Model C

....

Model N

Model O

 

Receiving.txt has anywhere from 800-1500 lines depending on the day.

"Serial number of unit" APP-Model-A 13.3/2.5/2X2GB/500-5400/SD 04FUNCTREC99 Processing Config-Manager, Default 3/3/2016 7:00:56 AM
"Serial number of unit" APP-Model-A 13.3/2.5/2X2GB/500-5400/SD 04FUNCTREC99 Completed Config-Manager, Default 3/3/2016 7:01:37 AM
"Serial number of unit" APP-Model-A 13.3/2.5/CTO 04FUNCTREC99 Processing Config-Manager, Default 3/3/2016 7:02:18 AM
"Serial number of unit" APP-Model-A 13.3/2.5/2X2GB/500-5400/SD 04FUNCTREC99 Processing Config-Manager, Default 3/3/2016 7:06:25 AM
"Serial number of unit" APP-Model B 11.6/1.6/4/128FLASH 04FUNCTREC99 Processing Config-Manager, Default 3/3/2016 7:08:29 AM
"Serial number of unit" APP-Model F 11.6 CTO 04FUNCTREC99 Processing Config-Manager, Default 3/3/2016 7:08:29 AM
"Serial number of unit" APP-Model G 13.3/2.9/2X4GB/750-5400/SD 04FUNCTREC99 Processing Config-Manager, Default 3/3/2016 7:09:10 AM
"Serial number of unit" APP-Model C 13.3/2.5/2X2GB/500-5400/SD 04FUNCTREC99 Processing Config-Manager, Default 3/3/2016 7:09:51 AM
"Serial number of unit" APP-Model M 13.3/1.6/4/128FLASH 04FUNCTREC99 Processing Config-Manager, Default 3/3/2016 7:09:51 AM
"Serial number of unit" APP-Model K 13.3/1.6/4/128FLASH 04FUNCTREC99 Processing Config-Manager, Default 3/3/2016 7:10:32 AM

 

 

I've already got it to where it is taking the second column and separating the "APP-Model-A" to just have strictly the models in an array.

Hope this is enough.

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

Here is a secret with the Read Text File that will make your life a little easier.  Right-click on the node and you will see an option to "Read Lines".  Set the count to read to -1 and you will have an array of strings, each element being a line from the file.


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
0 Kudos
Message 6 of 11
(3,496 Views)

Thank you Knights of Ni. What you provided is working for now but numbers are incorrect according to me adding the receiving up manually in Excel. But I should be able to decipher from here and move on. 

But FYI: I put a probe after set variant, coming up with wrong amounts. So maybe my data retrieval is wrong? 

'Model-A' ->10 but it should be 24 according to excel.

 

0 Kudos
Message 7 of 11
(3,485 Views)

From the text file you posted above, you have the dash in Model-A but no dash in Model B. Could you have both "Model-A" and Model A"?

0 Kudos
Message 8 of 11
(3,479 Views)

@crossrulz wrote:

As far as couting the different models, Variant Attributes work extremely well.

 


In my experience, variants are overkill. A simple sum of an array of 0s and 1s does the trick much faster.

Sum Boolean Array.png

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


Message 9 of 11
(3,455 Views)

There should be dashes. Which is why I mentioned my data retrieval was wrong in one of the replies. It actually was wrong since I noticed the numbers were not adding up. I fixed the problem and now everything works. 

 

Thanks Knights of Ni for the example and KLutz for helping me realize that there was a problem with the data. I didn't noticed it until you mentioned it.

0 Kudos
Message 10 of 11
(3,442 Views)