LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Error code 1 while writing to text file

Solved!
Go to solution

I have an error code 1 when I try to write to a text file in my application. I really don't understand and don't know how to fix this problem.

If anyone can please help me fix this problem, it would be greatly appreciated!

Download All
0 Kudos
Message 1 of 8
(5,055 Views)

Where is the error actually occurring?

 

I find it very odd how many times you branch some wires outside of structures then pass them into the structure through multiple tunnels.

 

It is also odd that in the default 0 case, you write to the file, close it, then read from it. (but not open it again, but that may occurr automatically), then close it again.  Why?

0 Kudos
Message 2 of 8
(5,041 Views)

sorry about the tunnels.

the first vi that I use to write is because I am trying to make an xml in a txt file and these are the first lines and in the second case I want to enter information in between these lines and also srite it to the same text file.

The error occurs in the second write to text file vi.

0 Kudos
Message 3 of 8
(5,037 Views)
Solution
Accepted by topic author Nando88

Don't close the file in case 0.  Only close it after your while loop is done.  Keep your file refnum stored in a shift register.

 

My guess is that you open the file outside the while loop and you pass in the refnum and use it within case 0.  Then you close the file which kills the refnum.  You then open the file again (possibly automatically with the Read) then close that.  When you get to case 1, you use the same refnum that you originally opened up outside, but that has been closed and is now invalid.

Message 4 of 8
(5,020 Views)

I will try that and let you know how it goes.

Thanks for your quick response.

0 Kudos
Message 5 of 8
(5,012 Views)

now it gives error 8 when I close the file.

Download All
0 Kudos
Message 6 of 8
(5,004 Views)

This is a prime example of how to NOT use local variables!  Its not that local variables are "Evil" but, that is a really poor use!  Once written in parallel to the main loop (Absolutely no data dependancy to the main loop so it can be written FALSE once at any time!) Once Written TRUE in the main loop (But only if both Paths are not empty strings and a float cast to int is exactly 1) and Once read as a loop termination condition.  AND- get this, the USER can't even see the control since it is hidden!

 

Yes, you need to re-think that vi a bit. 


"Should be" isn't "Is" -Jay
0 Kudos
Message 7 of 8
(5,002 Views)

Why are you still closing the file and then reading it in case 0?  You are going to get back exactly what you just put in.  Get rid of the close and the File Read.

Message 8 of 8
(4,992 Views)