LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

open file check

Hi, I'm using the Open/Create/Replace File.vi. I have it set up so that once the user clicks a button to start logging data, the Open/Create/Replace File.vi is called. Once this is called a window pops up asking the user where to save the file. Is there a way to check whether or not the user pushes the cancel button?


Also, is there a way to check if the file is open? I'm using an event structure, and sometimes I will click on the button to stop recording data, which will trigger the event structure to close the file, but as soon as it's finished closing the file the code will resume where it left off which in some cases it will try to write to the file (which is already closed) and I get an error message.

Thanks!

Sunny
0 Kudos
Message 1 of 5
(3,285 Views)
Check the "new file path" output from the Open/Create/Replace VI to see if its "Not a Path", this will indicate the dialog box was canceled.

In the "Comparison" palette is a function called "Not a Number/Path/Refnum". When a file is closed its refnum becomes invalid. Just use this function to check before attempting a write.

Good Luck.
Message 2 of 5
(3,277 Views)


@sunny dee wrote:
Hi, I'm using the Open/Create/Replace File.vi. I have it set up so that once the user clicks a button to start logging data, the Open/Create/Replace File.vi is called. Once this is called a window pops up asking the user where to save the file. Is there a way to check whether or not the user pushes the cancel button?


Also, is there a way to check if the file is open? I'm using an event structure, and sometimes I will click on the button to stop recording data, which will trigger the event structure to close the file, but as soon as it's finished closing the file the code will resume where it left off which in some cases it will try to write to the file (which is already closed) and I get an error message.

Thanks!

Sunny




The proper way would be actually to investigate the error cluster. On a user cancel the error status is true and the error code is 43 (user operation canceled). Checking for an invalid path is possible too, but it is not necessarily a fool proof check for all versions and has at least a small theoretical chance of breaking in some future LabVIEW versions.

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 3 of 5
(3,263 Views)
thanks for the suggestions...

now, i'm wondering: is there a way to jump out of my loop once i see that the file open has been cancelled? I can't just wire up the stop button of my while loop because if I do then the rest of the code in the loop will still execute, but I want it to just jump right out of the loop.

Here's the file if it's any help to see it.

Thanks again!
0 Kudos
Message 4 of 5
(3,246 Views)
nvm... i managed to figure it out.

thanks again!

sunny
0 Kudos
Message 5 of 5
(3,240 Views)