LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Excel read folllwed by a write error file open

Solved!
Go to solution

I'm trying to check if I'm overwriting a certain column before I write to it. It reads fine and tells me what's there but when I try to write over the data I get a file open error.Capture.JPG

 

I'm trying to check if I'm overwriting a certain column before I write to it. It reads fine and tells me what's there but when I try to write over the data I get a file open error.

 

 

0 Kudos
Message 1 of 4
(2,901 Views)

Most probably the report file has not been closed after previous run here or in another part of the program.

 

Do you have Close report in false case of the second Case Structure? It is better to move it out to make sure it closes always.

(I can not open vi, I am at LV2011).

0 Kudos
Message 2 of 4
(2,874 Views)

I solved it. I forgot to wire the file location in the Save Report File vi. Doh, I've been fiddling with this for days.

0 Kudos
Message 3 of 4
(2,867 Views)
Solution
Accepted by topic author DickHutchings

Here's my advice:

  • Start over!  Do not use any of the current code (which is "broken" in several ways,  and whose purpose and "intended function" cannot easily be deduced from looking (or running) the code!
  • Start small and add refinements as you go.  I'll suggest one way to do this, but feel free to vary from "what makes sense to me".
  • Let's start without a Case Statement, since we're "starting small", and concentrate on asking and answering the question "Are there data already in this Excel WorkBook's default WorkSheet.
    1. You are using LabVIEW 2017, so use the correct "Create Report" function from the RGT Palette.  [Did you notice the big red X over the New Report VI in your Block Diagram?  This means the function is "deprecated", i.e. no longer supported, so use something that is supported.]
    2. Create two Excel data files, one with no data, and one with some data.  You will use these to test your code.
    3. Decide on the Test you want to run.  Try to make the code for the test "obvious" to the reader (or to yourself).  In your case, you have a Control "Excel SMU_B" without a TypeDef, a Cluster having a Cluster for Excel Position and two Disabled Clusters whose name is written in 7pt type -- it took me a few minutes to figure out what they were!  Don't "hide" important details like this!
    4. Read up and understand how Excel Position works.  What cell/row/table do you want to read?  What cell/row/table is your code going to read?  Are they the same?  [I'm guessing Probably Not].  [Do you understand why I asked "cell/row/table"?  Do you know how to specify a cell, a row, or a table (rows & columns)?]  Be sure to wire Error Out to the end of the Error Line -- this is going to be very important shortly, and should be a practice in (almost) 100% of your LabVIEW VIs (when you become an Expert, you can consider omitting it).
  • OK, now you know how to read an existing file and determine something about it.  Is the determination you just did a "Yes/No" determination (are data there or not, as opposed to "are data there and of the form such-and-so, where there might be 3 (or more) choices depending on what data are found?
  • So now you need to decide what you want to do in each case.  Don't make it too complicated -- regardless of the outcome of the earlier test, generate one (or more) rows of data and try to add them to the existing Data File, whether or not there are data already there.  Generate a Constant (or a Front Panel Control that you initialize with fixed data, then select and in the Edit Menu choose "Make Selected Default" to "freeze" the data in place).  Don't worry about writing the file yet, just see if you can Append the data.  Look at the resulting Excel file -- does it look OK?
  • Once that works, add the Dispose Report to close Excel.  Note that you have not yet tried to Save Report to File.  Verify that you have not changed your Excel File.
  • Finally, add Save Report to File.  What happens when you run it?  If there's an Error, what is the only Function that could be causing it?  Read the Help description for that function, then fix any Error that might be present.

Once you've done all these things, you should largely have solved your quest.  Congratulations!

 

Bob Schor

Message 4 of 4
(2,844 Views)