05-04-2016 03:13 PM - edited 05-04-2016 03:14 PM
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!
Solved! Go to Solution.
05-04-2016 03:28 PM
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?
05-04-2016 03:35 PM - edited 05-04-2016 03:37 PM
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.
05-04-2016 03:55 PM
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.
05-04-2016 04:07 PM
I will try that and let you know how it goes.
Thanks for your quick response.
05-04-2016 04:20 PM
now it gives error 8 when I close the file.
05-04-2016 04:20 PM
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.
05-04-2016 04:31 PM
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.