LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Anyone know how to add a string to a 1d array with file info, then be able to read back, display string, and sort data array.

I need to store a data array and include text that describes what the data is. (using for various configuration files.) Anyway, I would like to be able to save the string as part of the txt file, and somehow read it back, remove the (various length string), and display it in an indicator. All the while, not causing too much problem with the initial data array.
Thanks in advance!!
0 Kudos
Message 1 of 3
(2,742 Views)
There are several ways to do what you require. A simple method would be to use an ASCII text file. When writing one of those, you just need to basically build a gaint string starting with the description text you want. We like to call that a header. Once you've got the header, make some sort of delimiter like a bunch of "-" or two sets of ( EOL = End of Line = CRLF = \r\n ). After your delimiter, concatenate your array in string form or flatten your array from its native form into a string and tack it on the file (append).

See the (very quick) example attached.

Dan Press
www.primetest.com
0 Kudos
Message 2 of 3
(2,742 Views)
If you dont mind mixing data types, you can use such a multi-line text header and end it with something you choose (like "" on a line alone). Then you can write the arrays to the same file stream refnum.

When reading them back, you can use the generic file read, in line mode, until you read "". Then, starting from offset (current bytestream position), you can read the rest of the data using the appropriate data type.

This is useful for large data sets that would make large text files or take a long time converting to strings. It may be useful to include the file structure you use in the text header for reference or for custom file readers capable of handling different file structures. I sometimes use this when I know the file
structure will probably change as the writing program is updated, but want a reader that can still open old file structure formats.
0 Kudos
Message 3 of 3
(2,742 Views)