Jump to content
Sign in to follow this  
star

writing to a text file

Recommended Posts

Hi all,

I have made a code that sends a number to a file, however if i send another number the previous number gets deleted and the new number gets stored. So i was wondering if anyone can help me and i have attached my code.

Thanks

Share this post


Link to post
Share on other sites

Sorry i forget to say what i want my code to do. I want it to keep on stored new numbers, while it keeps the old numbers stored in the same file (like a list).

Share this post


Link to post
Share on other sites

Changing the "access (0:read/write)" Enum input to the "Open/Create Replace File" function from "write-only (truncate)" to "write-only" seemed to solve the problem. I don't know if that item was available with that Enum in an older version of LabVIEW, but on my copy of LV 8.6 that Enum caused a coercion dot. Here's a slightly cleaned up version of your VI and a screenshot (in case you don't have LV 8.6). You might also want to concatenate a LineFeed at the end of each number.

Share this post


Link to post
Share on other sites

Yeah i am using version 8.5(thats ok), but the new number which i saved is on the same line as the previous one and i want it to be save on the next line. And if i want to save more numbers, it would be on the next line. I was thinking of using the tab function but i don't have alot of knowledge about it.

Thank you anyways

Share this post


Link to post
Share on other sites

if you want to write to the next line, write a end of line Constant to the file or concatanate it with the string you're writing.

You can also use the write to spread sheet file.vi. It offers the parameters append and tronspose which could be useful for you.

Share this post


Link to post
Share on other sites

The old NI File functions used to append data by default, and now the new ones overwrite by default. NI are you listening? Its sucks! (Sorry to be so grumpy)

Share this post


Link to post
Share on other sites

QUOTE (star @ Feb 23 2009, 12:30 AM)

when i did it, it work however it takes a while to execute and i have to keep the write button on before i run it and leave it on until it the code finishes. Is it possible for the code to run faster and also when i run the code, i want to wait until the user press write button and then end when the information is saved to the file.

The code will be faster if you open the file once and work with the reference.

Look at the event structure to realize the user interaction.

regards,

nicolas

Share this post


Link to post
Share on other sites

QUOTE (nicolasB @ Feb 23 2009, 07:19 AM)

The code will be faster if you open the file once and work with the reference.

Look at the event structure to realize the user interaction.

regards,

nicolas

Hi nicolasB

I have done some tutorials on events srtructures, however i don't know how to use it in this example.

Share this post


Link to post
Share on other sites

QUOTE (star @ Feb 23 2009, 10:02 AM)

Hi nicolasB

I have done some tutorials on events srtructures, however i don't know how to use it in this example.

Just a 5 minute example of your code with an event structure. Without error handling etc.

1. open file

2. press write?

Nicolas

Share this post


Link to post
Share on other sites

QUOTE (nicolasB @ Feb 23 2009, 10:23 AM)

Just a 5 minute example of your code with an event structure. Without error handling etc.

You were faster than me, but mine keeps the filename constant and has comments which may be useful. I'll post it anyway since I've already done the work.

Share this post


Link to post
Share on other sites

It works, however this code was smaller part of a bigger code and when I executed the big code it work until it reached the writing file.vi. The reason why is the writing file.vi doesn't stop or the bigger code needs to be in an event structure. I attached the whole code so you could look it.

Thank you for version 8.5

Share this post


Link to post
Share on other sites

QUOTE (star @ Feb 24 2009, 03:09 PM)

It works, however this code was smaller part of a bigger code and when I executed the big code it work until it reached the writing file.vi. The reason why is the writing file.vi doesn't stop or the bigger code needs to be in an event structure. I attached the whole code so you could look it.

Thank you for version 8.5

Can someone start me off to make this code in a sequence structure and using event structure as well.

Please

Share this post


Link to post
Share on other sites

I'm still using LV 8.2, therefore, I couldn't see the solutions posted.

Here's one way of accomplishing this (see attachment)

Share this post


Link to post
Share on other sites

Hello star,

So are you saying the 'Write File Y.vi' or 'Write File X.vi' hangs? If so, where does it hang? To troubleshoot this, in a 'hung' piece of code, put the 'highlight execution' tool on. A green arrow will be over the 'vi' that is hung. Could you try this, and provide a little more detail with regards to your request?

Best of Luck,

Justin

Share this post


Link to post
Share on other sites

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.

Sign in to follow this  

×
×
  • Create New...

Important Information

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