LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to close a CSV file if it is already opened.


@sportsguy99 wrote:

The file name can be changed or could be the same based on the operator's wishes. Thats not important. The GUI can append to a already existing file. But it can only write new data when the CSV file is closed. I only need to make sure the file is closed at the start of the program. Thats the problem, I am having.


Isn't appending writing new data to the end of a file?

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 11 of 39
(1,439 Views)

Yes it is writing to the end of the file. That is fine. I have the program working perfectly but when the file is open, a popup keeps arising saying "file is opened and cannot write new data" or along those lines. I just wish to close the file in the beginning of the program.

0 Kudos
Message 12 of 39
(1,430 Views)

@sportsguy99 wrote:

Yes it is writing to the end of the file. That is fine. I have the program working perfectly but when the file is open, a popup keeps arising saying "file is opened and cannot write new data" or along those lines. I just wish to close the file in the beginning of the program.


OK, Now things are making sense (maybe- but, I have an exceptionally accurate 8-Ball)

 

A "The File may be opened in another application! Close the file and try again." error.  As Ben mentioned in the first reply, only the owning application can close the file.  

 

Spoiler
All software is perfect until you introduce a "User"!

"Should be" isn't "Is" -Jay
0 Kudos
Message 13 of 39
(1,424 Views)

Yes you are correct. I want to do this for the owning application. I still want to make sure the file is closed. 

0 Kudos
Message 14 of 39
(1,416 Views)

@sportsguy99 wrote:

Yes it is writing to the end of the file. That is fine. I have the program working perfectly but when the file is open, a popup keeps arising saying "file is opened and cannot write new data" or along those lines. I just wish to close the file in the beginning of the program.


This still does not make sense to me...

 

Program 1 opens a file and when it is done it closes the file, right?

Program 2 opens the file program 1 made, right?

 

Now you say program 1 tries to open the same file that is already has open or does program 2 still have the file open and program 1 is trying to open the same file again??

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 15 of 39
(1,411 Views)

I am not trying to open any file. I just need to make sure the Excel spreadsheet file is closed in the beginning of the program because the GUI will not append to the excel file without it being closed. I never open any files in this program. 

0 Kudos
Message 16 of 39
(1,408 Views)

You have managed to sump 6 of us (with probably 100 years experience combined) with the question.

 

I would use my magic-eight ball to answer (but it needs rehydrated).

 

Are you telling us that Excel has it open?

 

If that is the case you would have to find the Excel process(s) and close them using OS calls.

 

If is far easier to pop-up a message saying "File is open please close it and try again".

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 17 of 39
(1,403 Views)

Yes, that the file is opened in Excel. How would i use OS calls? Is there any other ways? I would rather not make a pop-up message.

0 Kudos
Message 18 of 39
(1,397 Views)

@sportsguy99 wrote:

I am not trying to open any file. I just need to make sure the Excel spreadsheet file is closed in the beginning of the program because the GUI will not append to the excel file without it being closed. I never open any files in this program. 


If you are not opening any files then who is opening the file in Excel?

 

Sounds like a training issue to me. You have to close the file in Excel before you launch your "GUI" program.

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 19 of 39
(1,394 Views)

Yes, but I want to make my program robust in case of errors if another user uses the program. Just in case they have the file opened when running the GUI, i want my program to close the file.

0 Kudos
Message 20 of 39
(1,389 Views)