Write to Text File issue
#1
Posted 21 October 2011 - 07:18 AM
#2
Posted 21 October 2011 - 08:12 AM
I'm not sure I completely understands your question, but just calling the "Write To Text" method replaces any previous content (see help).when use this vi to write my data,why the data i had written don‘t exist。it just remain the data i just write。what did it happen? why this vi don't need close vi but the key need ?thanks very much
If you want to append new data to the file you'll have to;
- Open the file with "Open/Create/Replace file"
- Move the pointer to the end of file using the "Set File Position"
- Write new data with "Write To text file"
- Close file refnum
Edited by Mellroth, 21 October 2011 - 08:12 AM.
#3
Posted 21 October 2011 - 09:05 AM
for your information,i understand i maybe forget the "Set File Position"。I'm not sure I completely understands your question, but just calling the "Write To Text" method replaces any previous content (see help).
If you want to append new data to the file you'll have to;/J
- Open the file with "Open/Create/Replace file"
- Move the pointer to the end of file using the "Set File Position"
- Write new data with "Write To text file"
- Close file refnum
but i’m puzzled because i didn't Close file refnum, its running is ok. so whether i must add “close File”,if i don‘t use it,what will happen?
#4
Posted 21 October 2011 - 10:20 AM
You should always close references that you open (better safe than sorry), this is true for Files as well as Queues, Notifiers etc..for your information,i understand i maybe forget the "Set File Position"。
but i’m puzzled because i didn't Close file refnum, its running is ok. so whether i must add “close File”,if i don‘t use it,what will happen?
If you don't close a refnum, and continuously open new references you have introduced a memory leak, that in the end can lead to a crash.
/J
#5
Posted 21 October 2011 - 11:59 AM
for your information,i understand i maybe forget the "Set File Position"。
but i’m puzzled because i didn't Close file refnum, its running is ok. so whether i must add “close File”,if i don‘t use it,what will happen?
That API is 'smart' it allows you to read/write using the single VIs and LabVIEW handles all the opening and closing of references in the background.
However if you want more control e.g. streaming data to disk in a loop - so you dont want to open and close a reference everytime - you can explicitly handle it yourself.
#6
Posted 24 October 2011 - 09:20 AM
oh,i see, thanks very muchThat API is 'smart' it allows you to read/write using the single VIs and LabVIEW handles all the opening and closing of references in the background.
However if you want more control e.g. streaming data to disk in a loop - so you dont want to open and close a reference everytime - you can explicitly handle it yourself.













