codcoder Posted December 20, 2024 Report Posted December 20, 2024 (edited) Hi, So I had a bug I couldn't figure out. The setup is according to the attachment. The Close File function kept throwing an error (code 1) and I couldn't understand why. But then I finally understood: if there is an error in to the Write to Text File the file refnum becomes invalid. The reason I am starting this thread is that I always thought that there is always a case structure in a sub VI, even for the primary functions, so that if there is an error the function isn't executed BUT any refnum passes the VI unaffected. But that isn't the case? Is this an expected behaviour? Edited December 20, 2024 by codcoder Quote
drjdpowell Posted December 20, 2024 Report Posted December 20, 2024 7 hours ago, codcoder said: if there is an error in to the Write to Text File the file refnum becomes invalid I just checked, and it doesn't close teh file reference, but it does pass out a null reference. The original reference is still valid. This is still unexpected behavior, though. Quote
ShaunR Posted December 21, 2024 Report Posted December 21, 2024 (edited) You are probably getting a permissions error on the Open (windows doesn't ordinarily allow writing "c:") which will yield a null refnum and an err 8 on the open. Your err 5000 becomes a noop as does the write. You're then clearing that error so when you come to close the null refnum it complains it's an invalid parameter - equivalent to the following. Is it expected behaviour? Yes. Should it report a different error code? Maybe. Edited December 21, 2024 by ShaunR 1 Quote
codcoder Posted yesterday at 07:33 AM Author Report Posted yesterday at 07:33 AM On 12/21/2024 at 1:37 PM, ShaunR said: You are probably getting a permissions error on the Open (windows doesn't ordinarily allow writing "c:") Actually I am not. I just added the constant "c:\text.txt" to this example but I have confirmed that I have write privilege to the folder on my computer. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.