LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Failure to read multiline string with Read Key.vi

I converted 2D array into a spreadsheet string and attempetd to write it as a key value into a configuration file. This worked just fine. However, when I attempted to read this multiline string using Read Key.vi, I got just the first line in return (see two vi's attached).

As sufficient documentation on configuration file vi's is all but missing, could you please advise on their (undocumented) features? What do I miss?

Thank you.

Michael
0 Kudos
Message 1 of 7
(4,372 Views)
The configuration file expects each key to be on one line...When you write the spreadsheet string it separates the rows using CR LF, but the read key function will interpret the first end of line to be the end of the key.

One way to solve this is to write the key as raw data (input to the write key function). It will then be written with display codes instead of an actual cr lf. The read key will then read all the numbers, however you will need to replace the display codes with CR LF prior to converting it to an arry using the spreadhseet string to array.
0 Kudos
Message 2 of 7
(4,372 Views)
Information on configuration files can be gotten from Microsoft (thoogh I don't have the web page hany right now). As an alternative to what Mads suggested, naother technique is to first write a key that has the array size and then for each element in your array, write a key with a unique name (i.e. element0, element1, etc.). This would be done in a loop with the key name changed for each iteration. Then when you want to read the values back, first read the key that has the array size and then execute a loop that many times that reads each element's value. The advantage of doing it this way is that the contents of the .ini file are a little clearer if you want to look at it from a text editor.
Message 3 of 7
(4,372 Views)
Hi Michael,

MichaelS wrote in news:506500000008000000F7980000-
1042324653000@exchange.ni.com:

> I converted 2D array into a spreadsheet string and attempetd to write
> it as a key value into a configuration file. This worked just fine.
> However, when I attempted to read this multiline string using Read
> Key.vi, I got just the first line in return (see two vi's attached).

I use Config files all the time. Much more user-friendly than the
Registry. They are a Microsoft thing really, rather than LabView, and
come from Windows 3.11. Each value is limited to one line, so when you
write a spreadsheet string with end-of-line characters in it, you're
effectively breaking the .inf file 😞

The solution? Try putting a "Search and Replace String
" after your
"Array To Spreadsheet String". Wire "Replace All" with a TRUE constant,
and wire "Search String" with a string in "\" view and enter \r\n (or do
0A0D in Hex view) and then then wire Replace String with a ";"

Now your .inf file will look like:
[Array]
Data=1.0000,0.0000,0.0000;0.0000,2.0000,0.0000;0.0000,0.0000,3.0000;

When reading it, just reverse the search and replace strings above.

I hope this helps,

Andrew
Message 4 of 7
(4,372 Views)
Thank you, this is usefull.

Regards,
Michael
0 Kudos
Message 5 of 7
(4,372 Views)
Followin' up to my own post? Bad man!

Andrew Tait wrote in
news:Xns93CAA4CA6F137supportsuercglaacuk@130.164.140.31:

> MichaelS wrote in news:506500000008000000F7980000-
> 1042324653000@exchange.ni.com:
>
>> I converted 2D array into a spreadsheet string and attempetd to write
>> it as a key value into a configuration file. This worked just fine.
>> However, when I attempted to read this multiline string using Read
>> Key.vi, I got just the first line in return (see two vi's attached).

> The solution? Try putting a "Search and Replace String" after your
> "Array To Spreadsheet String". Wire "Replace All" with a TRUE
> constant, and wire "Search String" with a string in "\" view and enter
> \r\n (or do 0A0D i
n Hex view) and then then wire Replace String with a
> ";"

In case the above doesn't read well, here's an HTML output of what I
did:

http://www.antait.pwp.blueyonder.co.uk/Save2D.html

Cheers!
0 Kudos
Message 6 of 7
(4,372 Views)
So I am not the only one that uses this approach.

It works good for savings arrays of clusters as well. I just postpend the number to the cluster element name.

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 7 of 7
(4,372 Views)