From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

'write to spreadsheet' VI error: File already open

Solved!
Go to solution

I get this error when I am writing to a CSV file: I record data there continuously... well I have programmed that it stores about 100 points in the memory and writes every 100 points.

 

When I open the recorded file, for example in notepad to preview it, Labview returns the error "File is already open" and hence it cannot write. 

Isnt this weird? Arent you just caching the file info when opening? How do I solve it?

 

I am using the 'write to spreadsheet' VI.

 

Thanks

 

0 Kudos
Message 1 of 11
(4,520 Views)

No it isn't weird.  Notepad has the file opened.  How can Labview open it for writing?  Can't be done.  Close Notepad before running Labview.  When you want to view the file, pause Labview, open the file with Notepad, then close Notepad before resuming Labview.  A big pain! Smiley Mad

 

The workaround is to create code in labview to read the file and display the contents in an indicator.  Then you can see the new writings on the fly.

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 2 of 11
(4,515 Views)
An alternative is to use Notepad++. It caches the file it reads, so you can still write to it. If you switch application focus from Notepad++ and then back into Notepad++ then Notepad++ will detect the file has been updated and asks if you want to reload it.
Message 3 of 11
(4,497 Views)

smercurio_fc wrote:
An alternative is to use Notepad++. It caches the file it reads, so you can still write to it. If you switch application focus from Notepad++ and then back into Notepad++ then Notepad++ will detect the file has been updated and asks if you want to reload it.

... Or just do the old fashioned thing, copy the file you want to check, open and view the copy and continue to write to the original.

I haven't had problems with this method yet.

 

Funny how this error never appears for me in my config file code. (Maybe beacuse I have all the file data cached in a FGV I can just write all the data to the file again whether it is opened by notepad or not!) Smiley Wink

 

James

CLD; LabVIEW since 8.0, Currently have LabVIEW 2015 SP1, 2018SP1 & 2020 installed
0 Kudos
Message 4 of 11
(4,485 Views)

smercurio_fc wrote:
An alternative is to use Notepad++.

 


What is Notepad++?  Does it come with some version of Windows?

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 5 of 11
(4,475 Views)

tbob wrote:

smercurio_fc wrote:
An alternative is to use Notepad++.

 


What is Notepad++?  Does it come with some version of Windows?

 


No, it doesn't. It's a free editor designed to be a replacement for Notepad.

0 Kudos
Message 6 of 11
(4,472 Views)

Notepad++ looks good. Thanx,

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 7 of 11
(4,458 Views)

Guys, thanks for the replies.

 

As a matter of fact I dont WANT to see the file when writing. But I'm building a commercial app and it will probably happen once or twice when users will try to open a file that is being written to.

So if I cant avoid the error when opening, maybe I can prevent the user from opening the file by setting permissions? I will try this and report. Other suggestions are welcome.

 

Felix

 

0 Kudos
Message 8 of 11
(4,440 Views)
Solution
Accepted by topic author _Faust
Perhaps when you get the error, store what you were going to put into that file into memory or a temporary file.  Pop up a dialog that doesn't halt your program telling people not to open the file.  When your program detects the file is no longer open giving the error, then write out all that you stored in memory (or read from the temp file and write it out) before appending the newest data to the file.
0 Kudos
Message 9 of 11
(4,432 Views)
I really like your solution, thank you for your input. Will do so!
0 Kudos
Message 10 of 11
(4,416 Views)