LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing Numbers to a text file readable by Notepad

Hi!

I have three numbers (DBL) which I need to write to a TEXT (.txt) file. The file may be NEW or EXISTING (in which case the numbers have to be appended). The text file should open in Notepad.
The format should be: one set of three numbers in each line with a space (or comma) separating them.

For e.g. the text file should look like:

23.4, 4.7, 0.1
11.6, 5.9, 3.8
0.2, 0.0, 45.6
and so on.....

How can I achieve this? Which file open and write VIs to use?

Thanks!

- Gurdas
Gurdas Sandhu, Ph.D.
ORISE Research Fellow at US EPA
0 Kudos
Message 1 of 6
(3,209 Views)
Convert the numbers to text using the number to fractional string function...Now concatinate the numbers and include the necessary formatting characters in the string...in your case that would mean a concatination like this:

Number1 + , + Number 2 + , + Number 3 + End of line constant + Number 1 line 2 + Number 2 line 2......

If e.g. you have a table that has three columns, one for each of the numbers that is to go on one and the same line...you can generate the string row by row inside a for-loop and just place a 1-terminal concatinate outside with the auto-indexed output string array wired into it...and the result wired to the file IO...OR if you want to reduce memory usage etc. you can open/create a file first, then write the strings inside the loop an
d close when the loop is finished.

You write the string to a file using almost any file write function you want...you can use the open/create/replace function to open or create a file, then write at the end of that file..and close...or easier use the write characters to file function. If you write the data incrementally and very often (like in a fast loop) it better to use the basic functions because then the files won't be opened and closed on every iteration (as they would if you use the write characters to file function...).
Message 2 of 6
(3,209 Views)
Thanks Mads!

I figured out 2 more ways but yours is better than one of them atleast. That done, I am facing issues with file writing.
See my attached vi wherein I have mentioned the issues alongside the write vis.

Just to mention here:

1) When using "Write Chars to File" OR "Write to Spreadsheet File" how can I avoid error 43 if the user does not wish to write but does want the program to run and display.

2) When using "Write File" vi, what is the easiest way to ensure data is appended for already existing files? I used shift registers in the attached vi to achieve this but it would be difficult to use them in my mail program.

- Gurdas
Gurdas Sandhu, Ph.D.
ORISE Research Fellow at US EPA
0 Kudos
Message 3 of 6
(3,209 Views)
Answered the questions in the new thread you made, but here I've attached i picture of the code...The example susing write to...and the problem with the error...that's in the answer in the other thread.
0 Kudos
Message 4 of 6
(3,209 Views)
I still can't figure out the error 43 thing.
Did you try running my attached vi?

If the user cancels, the write chars and write to spreadsheet vis pop a dialogue box which when cancelled leads to error 43. This happens even if I use the file open/create/replace function instead of the simple file path control as in my attachment.

- Gurdas
Gurdas Sandhu, Ph.D.
ORISE Research Fellow at US EPA
0 Kudos
Message 5 of 6
(3,209 Views)
If you use the error output/inputs it won't show the error...the example I sent does not. The way to do it with write characters or any of the other all in one VIs is to not let them present the dialog. Use the file dialog function. If the user cancels the function outputs a cacelled boolean. Put the write in a case and wire the caceled output to the case...if it's true do nothing, if it's false write.
0 Kudos
Message 6 of 6
(3,209 Views)