LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why can I only save one time with report gen toolkit?

Solved!
Go to solution
I need to record data on an excel spreadsheet, and I would like to save the spreadsheet after each line of new data is written, or every few minutes.  The first time the spreadsheet is saved everything is fine, but any subsequent saves give me error code 5, which tells me the file is already open. Is this by design, or do I need to take additional steps before saving again?   

I attached a sample that illustrates what I’m trying to accomplish.

I am using LabVIEW 8.6 with the latest RGTK

Mike

0 Kudos
Message 1 of 7
(3,303 Views)

How are you running this VI?  Is it a subVI in a loop in another VI?

 

I think the problem is that if your try running it again, you get the error because the file is already open, just like the error says.Smiley Wink

 

You open up a report reference at the beginning of this VI, but you don't close it out at the end using the Dispose Report subVI.  So when you run it again, you are trying to reopen a file that is already open.

0 Kudos
Message 2 of 7
(3,280 Views)

Ravens Fan wrote:

How are you running this VI?  Is it a subVI in a loop in another VI?


 

The attached vi is just an example.

 

I’m trying to log data to a spreadsheet that the end user keeps open to monitor while data is logging.   I would like to save the spreadsheet after each line of data is written, which is every few minutes in order to prevent accidental data loss.  In the previous version of RGTK saving the spreadsheet more than once while it was still open was not a problem.  This issue showed up when my customer upgraded to LabVIEW 8.6 and new version of the toolkit that uses classes.

 

Anyway, I was able to put in a band-aid fix by modifying the Excel save vi in the toolkit to ignore error 5.  It’s not the best solution, but it will work until a better one comes along.

0 Kudos
Message 3 of 7
(3,268 Views)

Hello M Kepple,

 

This error is derived from the Open/Create/Replace.vi that is located in the Save to Report file.  This VI cannot open or replace a file if it is already open.  In your program you don't close the file.  If you are only writing to a file about once a minute I would recommend closing and opening it each time.

 

Note: If you are writing to this file very frequently do not do this.  I am still looking for a better work around for you as well.

 

Regards,

Jon S.
National Instruments
LabVIEW NXG Product Owner
0 Kudos
Message 4 of 7
(3,244 Views)
Solution
Accepted by topic author M Kepple

Mike,

 

I agree with you that the behavior is incorrect.  Even with a dispose report at the end, the error is still reproducible.  The user should not have to put a close file reference in code when using RGT.  After playing with the VI, it seems that the mechanism implemented to prompt the user to overwrite an existing file if the 'Prompt to Replace' function on the save is a 'True' is causing problem.

 

I modified my VI to the following, and it works fine (I tested in a for loop to save 100 times in a row with no problems Smiley Happy) The only issue is now the prompt to replace function is nonfunctional. If you need this, let me know and I can throw a quick workaround in to allow for that.

 

 

I will be filing a Report to R&D that the operation is not working as intended, if I hear anything back, I will surely let you know, but for now this should make everything work out for you, without having to ignore error codes(bad!)

Message Edited by Robbob on 04-04-2009 09:27 PM
Rob K
Measurements Mechanical Engineer (C-Series, USB X-Series)
National Instruments
CompactRIO Developers Guide
CompactRIO Out of the Box Video
0 Kudos
Message 5 of 7
(3,214 Views)
Wow, is THIS one of the most timely posts EVER!  I am having the same problem except that mine is very intermittent. While the user will not ordinarily execute the Save Report to File very often, I get that error occasionally, whether a lot of time (>1 minute) has passed or not.  I had tried everything, and I HAD included the Dispose Report after the Write to Report.  So if I undertand you correctly Rob, you just completely deleted a lot of the code (select, open/create/replace file, close file and delete file, as well as the inner case structure?  To be safe, is there any way you could post that modified VI?  It would be a huge help!
0 Kudos
Message 6 of 7
(3,003 Views)

Hello Dan,

 

I don't have the exact code that Rob created but it appears to me that all he did was remove the case structure and the File I/O functions.  If you look in the subVI that is on this diagram it simply uses the SaveAs ActiveX method to save the notebook, so each time you call this VI you are simply calling the ActiveX method and saving the VI, even if it is open.

Regards,

Jon S.
National Instruments
LabVIEW NXG Product Owner
0 Kudos
Message 7 of 7
(2,984 Views)