Jump to content


Photo
- - - - -

Write to Text File issue


  • Please log in to reply
5 replies to this topic

#1 bulebell

bulebell

    More Active

  • Members
  • PipPip
  • 28 posts
  • Version:LabVIEW 2009
  • Since:2009

Posted 21 October 2011 - 07:18 AM

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

#2 Mellroth

Mellroth

    The 500 club

  • Members
  • PipPipPipPipPip
  • 535 posts
  • Version:LabVIEW 2011
  • Since:1995

Posted 21 October 2011 - 08:12 AM

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;
  • 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
/J

Edited by Mellroth, 21 October 2011 - 08:12 AM.


#3 bulebell

bulebell

    More Active

  • Members
  • PipPip
  • 28 posts
  • Version:LabVIEW 2009
  • Since:2009

Posted 21 October 2011 - 09:05 AM

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;

  • 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
/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?

#4 Mellroth

Mellroth

    The 500 club

  • Members
  • PipPipPipPipPip
  • 535 posts
  • Version:LabVIEW 2011
  • Since:1995

Posted 21 October 2011 - 10:20 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?

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

#5 jgcode

jgcode

    LabVIEW Renegade

  • OpenG
  • PipPipPipPipPipPip
  • 2,397 posts
  • Location:Australia
  • Version:LabVIEW 2009
  • Since:2005

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 bulebell

bulebell

    More Active

  • Members
  • PipPip
  • 28 posts
  • Version:LabVIEW 2009
  • Since:2009

Posted 24 October 2011 - 09:20 AM

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