Jump to content

Write to Text File issue


Recommended Posts

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

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;

  1. Open the file with "Open/Create/Replace file"
  2. Move the pointer to the end of file using the "Set File Position"
  3. Write new data with "Write To text file"
  4. Close file refnum

/J

Edited by Mellroth
Link to comment

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;

  1. Open the file with "Open/Create/Replace file"
  2. Move the pointer to the end of file using the "Set File Position"
  3. Write new data with "Write To text file"
  4. Close file refnum

/J

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?

Link to comment

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?

You should always close references that you open (better safe than sorry), this is true for Files as well as Queues, Notifiers etc..

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

Link to comment

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.

Link to comment

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.

oh,i see, thanks very much

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.