LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I open a file conditionally

How do I conditionally open up a file.  I am trying to use a true/false case statement, but in the false case, I have 2 errors, an unconnected error and an unconnected refnum. So I have 2 unconnected tunnels.  Also, my write to file is in a while loop, so is there a consequence of writing to a file I didn't even open.  I can't put my write to file icon inside the case statement with the file dialog open. 

 

Navman.

0 Kudos
Message 1 of 4
(2,604 Views)

@navman wrote:

How do I conditionally open up a file.  I am trying to use a true/false case statement, but in the false case, I have 2 errors, an unconnected error and an unconnected refnum. So I have 2 unconnected tunnels.  Also, my write to file is in a while loop, so is there a consequence of writing to a file I didn't even open.  I can't put my write to file icon inside the case statement with the file dialog open. 

 

Navman.


How do you conditionally open up a file?  It depends.  (Haha, a little humor there.)  Actually, can you post the VI so we can better understand the issue(s) you are having?

 

Thanks.  🙂

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 4
(2,601 Views)

Simply based on the limited information in your post, you want to wire the error cluster through and us a Not a Refnum Constant (found in the File palette) for the reference.  At the write part, you can either perform a check for Not a Refnum (there's a primitive in the Comparison palette that does that) or simply handle the error that will ensue.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 4
(2,598 Views)

If you're using the file functions with a refnum you must 1st use Open file to get a refnum. If you dont need to keep writing to a file it's easier to just wire a path to write file, in which case it'll open, write and close itself. For lots of writing that's inefficient and you'll better use the refnum instead.

 

As for the case structure, just like you need to open a file and connect it to write file and close file you'll need to do the same when it's inside a case, the difference being that in the other case those wires goes straight through without any function.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 4
(2,591 Views)