LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

read cell value from Excel for multiple files

Solved!
Go to solution

I'm trying to write a LabView routine to read a specific cell value from an EXCEL worksheet file. I'd like to plot the value then move onto the next EXCEL file in the folder.  In one of the forums I found this LabView VI that works to read a cell value from a single EXCEL file called Read_Value_From_Excel.JPG

 

I tried to modify the program by adding a For Loop and List Folder function as shown in Read_Value_From_Excel_LM2.JPG.  This file gives me an error message indicating "Incorrect function in Read_Value_From Excel_LM2". 

 

I would appreciate any help as I've been struggling with this for a few days and haven't been able to find a similar question in the other forums. Thank you.

 

 

Download All
0 Kudos
Message 1 of 23
(3,825 Views)

I see two major problems with your code.

 

In both screenshots, you are closing all of your references as pretty much the same time.  There is a race condition as to which of the close functions executes first.  You need to close your references in the reverse order of how they were opened.  Otherwise you'll wind up closing a higher level reference such as a worksheet before you close a lower level reference such as  a range in that worksheet.

 

The second problem is that you are closing the application reference inside the For Loop, but you need that reference again in the next iteration of the For Loop.  The close application reference should be after the For Loop.

0 Kudos
Message 2 of 23
(3,821 Views)

Ravens Fan, thank you for your reply. I think I understand your comment that EXCEL is being closed before all of the files are processed, I can see that when I use the step thru function to run the program. 

 

I tried simply moving the Invoke Node for closing the application outside the For Loop and I can't get my wiring correct. I tried a few different permuations and couldn't get things to work. I'd really appreciate additional comments as I'm pretty stuck.

 

Attached is the .vi file (with the broken wiring). I'm using LabView 8.6. Thanks again.

0 Kudos
Message 3 of 23
(3,786 Views)

Right click and select 'Disable Indexing' on the top two exit terminals and the broken arrow goes away.  You only need to close 1 Application reference not an array and to do this you only need 1 error cluster not and array.

 

Hope this helps

 

Ken

0 Kudos
Message 4 of 23
(3,779 Views)

Ken's answer is correct about how to fix your broken wire issue.

 

But you still haven't fixed the problem with trying to close all the references at the same time.  Please look in the example finder for Excel examples so you can see the proper way to do it.  You should  be using the error wire to define the order of execution of all those close reference functions rather than having them all wired in parallel by splitting the error wire.

0 Kudos
Message 5 of 23
(3,770 Views)

Raven's Fan and Ken, thank you very much for your help. I'm still having trouble with the "close reference" functions.  From what I've read I think I should be closing the reference functions in the opposite order the nodes were open.  Am I on the right track to move some of the close references into the loop and leave the close reference for the application outside? Also, I removed the wiring for the error inputs and outputs so I can focus on getting the close references correctly wired. 

 

Thank you again.

 

 

0 Kudos
Message 6 of 23
(3,761 Views)

Yes you need to close the references in the reverse order and indeed moving them inside the loop will help but you still need to determine the order in which these references close by connecting the error cluster on each close reference with a single error cluster wire not multiple branches

 

Ken

0 Kudos
Message 7 of 23
(3,756 Views)

Hi,

 

I would say to use error wire to grant the right sequence order of closing the references. 

In your last vi, the reference can be closed even before getting the data out of the file.

 

Br,

Peter

0 Kudos
Message 8 of 23
(3,754 Views)

@GPeter wrote:

Hi,

 

I would say to use error wire to grant the right sequence order of closing the references. 

In your last vi, the reference can be closed even before getting the data out of the file.

 

Br,

Peter


That is exactly correct.  I don't understand why the OP didn't understand that when I said that in my previous messages.  Instead he decided to just ignore error handling altogether.  Sometimes I wonder what people are dreaming about when they read a message and come to a completely different conclusion about what they should be doing.Smiley Frustrated

 

People, when you are told to do something, please give us the courtesy of actually trying it out.  Ignoring suggestions doesn't help you solve your problems and just shows you don't value our time we put into helping you solve the problem.  If you are going to waste my time, what motivation do I have to continue helping you?

0 Kudos
Message 9 of 23
(3,746 Views)

Thank you very much for your responses.

 

Ravens Fan, I really apologize. I honestly wasn't trying to modify away from your suggestions. The problem is that I'm not fully understanding what all the functions are doing and so I wound up going in the wrong direction. I'm trying to use various resources off the Web to learn this but it's been slow going. I'll give the .vi another try based on the suggestions. Thank you again for all your patience.

0 Kudos
Message 10 of 23
(3,741 Views)