08-24-2015 03:20 PM
Hi,
I use the Report Generation toolkit to insert result graphs into a "Word document template at a predefined bookmark.
Using NI_ReportGenerationToolkit.lvlib:Word_Insert_Control.vi, I get the following error after an apparently random number of repetitions (ranging typically from 6 to 100+ repetitions):
***
Error 5 occurred at Delete in NI_ReportGenerationToolkit.lvlib:Word_Insert_Control.vi->NI_Word.lvclass:Append Control Image to Report.vi->Rapports.lvlib:TEST Append Control Image to Report.vi
Possible reason(s):
LabVIEW: File already open.
=========================
LabVIEW: File already open.
=========================
NI-488: Command requires GPIB Controller to be System Controller.
C:\Users\DCanQ\AppData\Local\Temp\lvtemporary_801332.jpg
***
It appears something (MSWord itself?) is sometimes keeping my temporaty image open and prevents "Word_Insert_Control.vi" from completing its tasks properly.
I have simplified the code as much as possible and made a loop around the "Append Control Image to Report.vi" to reproduce the error, and added the snippet here.
Is someone able to help me, please?
Thanks!
08-24-2015 03:55 PM
I use the RGT with Excel files. What I've observed is occasional errors or "hangs" if I try to open File 2 too soon after closing and disposing File 1. Try putting a 100 msec wait after your Dispose Report -- if that fixes it, start cutting the delay in half until you get something that works and feels comfortable to you.
Let us know if this "fix" works!
Bob Schor
08-25-2015 08:00 AM
Thanks for the reply Bob_Schor!
I tried adding 100ms delay, which failed at iteration 11, then at 200ms, to no avail either.
Just so you know, in my earlier attempts, I put a retry while loop around the Delete function in Word_Insert_Control.vi (the external dependency where the error initially occurs), but 10 seconds wait was not enough to succeed when it "hangs", while it normally takes around 50ms.
Also, in my actual application where I first encountered the problem, I line several Append Control Image to Report.vi before Dispose Report.vi, and the error shows up between Append calls.
08-25-2015 08:10 AM
If you attach your code, we could "play with it", see the error for ourselves, and try various things that "make sense" (as opposed to "guesses based on what we think you might be doing"). Since you are creating a Report (from something, I expect), it would be also helpful to have a sample data set, preferably one generating the failure. As this may be too many files for the Forum, put it all into a single folder and send us the Compressed File version of the folder. I'm curious to see this problem ...
Bob Schor
08-27-2015 10:59 AM
Hi,
Sorry for not replying sooner.
Here is the code the previous snippet was made from. The package contains a single vi plus a template document with bookmarks.
I reduced the code to its simplest expression except for debugging capabilities. All you need to do is set the template path.
The iteration count to fail is rather random (I even got to 1000 iterations once, but usually it takes between 1 and 100).
I left the "milliseconds to wait" control, but it doesn't seem to prevent failure, but only delay it in time.
Thanks a lot for the help!
08-27-2015 11:45 AM
That was fun! The code that you sent has (on my machine, Windows 7/64, LabVIEW 2014/32, Office 2010) the following characteristics:
I made two minor changes. Now:
I realize this might not be what you want to do (that is, pile all the iterations into the same file), but never mind.
The changes were as follows:
I also removed the Millisecond Wait, as it wasn't necessary since you weren't doing Open/Close/Open/Close cycles (and I don't know if Word has the same problem that Excel has, anyway).
See if any of this is helpful to you.
Bob Schor
08-27-2015 02:01 PM
Hi Bob_Schor,
I am glad you had fun while helping me, that must mean we both benefit in some way from our exchange. 🙂
Altering the sample vi as you suggest (moving New and Dispose Report outside the loop and not entering bookmark name) makes it indeed very fast and does not reproduce the error, but it may not be applicable to me.
Let me explain.
In the complete application, I use one main document and several templates that I fill according to the data sets selected by the user.
1. After filling the header page (lets say from Template A),
2. I open a first template page (e.g. from Template B),
3. fill it up with a number of graphs at the bookmarks (somewhat like in the last code sample),
4. merge A and B1 together,
5. close the template B without saving it,
6. open another template page (B or another one),
7.fill it with appropriate graphs and data,
8. merge with the previous A-B1 document,
9. close the second template without saving it,
10. Repeat until the last page is filled, and last template and main document are released.
I cannot create a single definite template because the number of each template is not fixed. I can have a report on this format, for example: A-B-B-B-C-C-C-C-C-D-D-E... or any other sequence.
I have used this mechanics in a software that ran for years, but I cannot find why this problem just showed up.
The error 5 codes happen when I am filling a template, at an apparently random time in the process descibed above, and at any "Appending" step at "Append Control Image to report.vi > Word_Insert_Control.vi > Delete".
The sample code I produced here contains the faulty VI from the Report Generation palette, presents the same error code and source on my machine (also Windows 7/64, LabVIEW 2014/32, Office 2010).
Please tell me if more info could help pin down the problem.
Thanks!
08-27-2015 02:47 PM
Hello again,
Right after sending the last reply, the optimized VI popped the error 5.
Here is an even simpler vi creating its own blank page to append graphs that get the same error, but in much less time. I think it's hard to get it leaner, and it is still not stable for me.
Could you try it out and tell me what you think?
Again, thank you.