LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Searching for Specified Data, Displaying Full Row from Excel

Solved!
Go to solution

Hello,

 

So I currently have a program that will search a pre-existing excel document (.csv) for a specified carrier number (cell value x). Once it finds the most recent carrier number it will display the part number associated with said carrier. I want to modify my code to allow me to search for the carrier number, and display the entire row (associated with that number. So say I search for carrier number in Column B, instead of just displaying the part number in Column E, I want to display the Row the data is located (A1:E1). Whether as a string or an array, I am just not sure how to go about setting it up. 

 

I attached the VI I currently have as a mock up that ONLY searches for the part number. To run the VI you'll need to change the Path to save dialog in the VI front panel. 

Download All
0 Kudos
Message 1 of 11
(1,865 Views)

If someone needs an earlier version of the labview vi, just lmk and I will save it as a previous version. 

0 Kudos
Message 2 of 11
(1,860 Views)

How about something like this?

 

Screenshot 2023-05-03 075254.png

 

========================
=== Engineer Ambiguously ===
========================
Message 3 of 11
(1,844 Views)

@paintman wrote:

Hello,

 

So I currently have a program that will search a pre-existing excel document (.csv) for a specified carrier number (cell value x). Once it finds the most recent carrier number it will display the part number associated with said carrier. I want to modify my code to allow me to search for the carrier number, and display the entire row (associated with that number. So say I search for carrier number in Column B, instead of just displaying the part number in Column E, I want to display the Row the data is located (A1:E1). Whether as a string or an array, I am just not sure how to go about setting it up. 

 

I attached the VI I currently have as a mock up that ONLY searches for the part number. To run the VI you'll need to change the Path to save dialog in the VI front panel. 


Hello Paintman,

 

If the file is of .csv (not excel) I recommend you use read delimited file and read all data.

 

If you still want to handle with excel, you can use as array (2D Array) and extract data using Array functions,

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
Message 4 of 11
(1,839 Views)

What array functions are you using in this? 

 

Would I need to place this in my case structure with the file path linked to it? I have never used the file I/O functions before. 

0 Kudos
Message 5 of 11
(1,824 Views)
Solution
Accepted by paintman

@paintman wrote:

What array functions are you using in this? 

 


Here's a snippet of block diagram with the labels turned on

 

Search CSV file.png

 


@paintman wrote:

Would I need to place this in my case structure with the file path linked to it? I have never used the file I/O functions before. 


Basically yes

========================
=== Engineer Ambiguously ===
========================
Message 6 of 11
(1,815 Views)

@paintman wrote:

What array functions are you using in this? 

 

Would I need to place this in my case structure with the file path linked to it? I have never used the file I/O functions before. 


Hello Paintman, I suggest you to go through LabVIEW Basics and also check help for the available BD Functions to understand better.

Just completing the task without understanding the basics will not help you in any way.

----------------------------------------------------------------------------------------------------------------
Palanivel Thiruvenkadam | பழனிவேல் திருவெங்கடம்
LabVIEW™ Champion |Certified LabVIEW™ Architect |Certified TestStand Developer

Kidlin's Law -If you can write the problem down clearly then the matter is half solved.
-----------------------------------------------------------------------------------------------------------------
Message 7 of 11
(1,811 Views)

I marked this as the solution because it ultimately gave me what I needed. 

 

But is there a way to dictate which direction it searches the spreadsheet? Since the values are organized based on time (FIFO) and the carriers will be used more than once, if I use carrier 48 earlier in the day, then again later. It will only show the first occurrence of the carrier #48. I know with Active-X I can specify which direction to search the data by, but is there a similar way to do this using the example you gave?

0 Kudos
Message 8 of 11
(1,767 Views)

Right off the top of my head I would do something like this:

 

Search CSV for more file.png

 

The For Loop uses Match Regular Expression and returns an array containing the indexes of all the rows that have the same Carrier. As long as they are entered chronologically you can Min/Max the array of indexes and the Max will be the most recent.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 9 of 11
(1,742 Views)

Just dawned on me that this would do the same thing, the simple equals comparison is faster than Match Regular Expression.

 

Search CSV for more file2.png

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 10 of 11
(1,702 Views)