LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Spreadsheet file is writing an extra new line that I don't want.

Solved!
Go to solution

777.png

Not sure why but despite stripping out all the new lines and carriage returns with regex combined with search and replace, there's still a new line being put in. There is supposed to be one invisible unicode character at the end of this I'm wondering if that's the problem. When I look at my indicator for the buffer that shows whats going into the Write Deliminated Spreadsheet, there are no newlines or carriage returns, evidenced by using the arrow keys and going through the string. Really stumped on this one hopefully someone knows this issue. I have another program that uses just about the same code and it doesn't have this issue which suggests it's something in this unique output that the device is putting out but I can't figure it out. The message originally looked like this "\r\u003e meas x\r\n\rx = 78.8 uT\n\r\n\r\u003e "

without the quotations, then the reg ex got it down to 78.8 uT so I'm wondering how there is those newlines in the file. Thank you.

Download All
0 Kudos
Message 1 of 10
(3,686 Views)
Solution
Accepted by topic author crash_override

Solved by putting the file writing code inside the case with the "After Match" string indicator.

0 Kudos
Message 2 of 10
(3,658 Views)

Untitled141.png

 Disregard that one I'm still getting the problem but with one less new line.

0 Kudos
Message 3 of 10
(3,641 Views)

Attach your VI.

 

A tiny screenshot of an Excel spreadsheet doesn't tell us what you're doing wrong.

0 Kudos
Message 4 of 10
(3,627 Views)

Ok I have it in the top reply but I will post the latest one that only has the one new line. Here's the newest csv as well.

Download All
0 Kudos
Message 5 of 10
(3,621 Views)

Sorry I have to remake this one because I thought I had it solved but I really did not. Some how there is a newline character being introduced into my Write Deliminated Spreadsheet file stream. Not really sure how. I have an indicator that shows me exactly what will be written before it gets written and no \n's or \r's that I can see. Was hoping if someone could look over the main loop and the file writing part to see if anyone can quickly figure it out.

91c6ae7235fc938a81db5070e47b993e.png

0 Kudos
Message 6 of 10
(3,614 Views)

I can't test it out and your code layout is hard to follow (wires going everywhere), but perhaps your Search and Replace is not doing what you wanted?  It will only replace the first "End of Line" constant because you have not wired a True to the "Replace All?" input.  It is also possible that you are not searching for the correct "end of line" type since on Windows it will search for a "\r\n" combination only.  I can only guess because you have not supplied any indication of the data going through.

0 Kudos
Message 7 of 10
(3,591 Views)

"\r\u003e meas x\r\n\rx = 78.8 uT\n\r\n\r\u003e "

this is what one line of the data coming out is. Really crazy I know. I apologize for the mess I'm kinda trying everything to get this part to work, probably the hardest thing so far. Weird, I had that set to true before I must have deleted it just to try and see what it would do. The reason the loop has to go through 11 iterations is, you send it a command "meas x" and it spits it back out at you one char at a time like so.

">"

"m"

"me"

"mea"

"meas"

"meas x"

"meas x = 42.7 uT"

with unicode 003e at the start and end. I will try your suggestion though I did have that set to true before not sure what happened. My hypothesis was that it was that the Write Deliminated Spreadsheet was introducing a newline after an iteration of the loop because in my other program where I'm writing two columns simultaneously it doesn't do that and it's basically the exact same code exact for that part.

 

0 Kudos
Message 8 of 10
(3,574 Views)
Solution
Accepted by topic author crash_override

Ok, so a couple of simple comments then I'll look at the end of line bits:

(numbered for reference in replies etc, not importance)

  1. You open the file and then pass in a file reference, but use "Refnum to Path" to get the path to write the file.  In the case that you don't find the pattern, you output a default file reference, which will leak your real reference.
    1. Directly write using the reference, not the path. This essentially means replace the "Write Delimited Spreadsheet" with "Write to Text File" and perhaps the Array to Spreadsheet function.
    2. Wire the reference through the case when you don't find matches (so the output is the same as in the input reference)
    3. Since you have only one line at a time you might not even need/want the Array to Spreadsheet String function - you can just directly Write to Text File (optionally appending a line end character if you don't have one.
  2. Once you've done the above, you may or may not still have a line-end problem, but it should be easier to see directly what you're writing. If it has too many line-end characters, you can use the Trim Whitespace VI that you're already using to remove them. You don't need a Search and Replace node.
  3. Set the termination character to a character you get at the end that you don't want to store (e.g. \x3e as a number, if that's always at the end) and handle the starting separately as needed (so perhaps drop the first message, which will be "\r\u00" and keep only the second message of each pair, " meas x\r\n\rx = 78.8 uT\n\r\n\r\u00" in your example case. Some testing will be needed to get this right probably, but it should be possible. If you always have a character at the end, use it as the termination character and your message handling will be much easier.
  4. I'm pretty sure you're right regarding WDS - I think it assumes that your array is one line, and so adds a newline afterwards. The following is copied from a comment inside WDS.

Array to Spreadsheet separates rows with EOL characters. If your spreadsheet application needs different terminators, use the Search and Replace from the String palette (or something equivalent) at the output of Array to Spreadsheet String to modify the string.

 

Since you're going to drop the WDS node (in favour of Write to Text File) and you may or may not need the Array to Spreadsheet String, this should be easier to appropriately handle.


GCentral
Message 9 of 10
(3,569 Views)

Wow you are a genius, array to spreadsheet was inserting a newline and I didn't know it. Don't think I would have gotten that any time soon. I followed everything you said and it works great now I'm really excited. Thanks for taking the time to look through that  mess I have cleaned it up and here it is.

0 Kudos
Message 10 of 10
(3,547 Views)