LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Display Commas In File

Solved!
Go to solution

Afternoon all,

 

Got what is hopefully an easy question and a lack of brain power on my part.

 

I have the following code which is designed to format three strings into one final string which then gets written to file. The file is comma separated. The file has column headers named Event, Date, Time and Value.

 

Display Commas.PNG

 

Now, this works perfectly apart from the fact that when it comes to write the final Value column data. Because there are commas in the final format into string function, it interprets this as shift to the next cell and write rather than it being one long string with the commas shown so I end up with this:

 

String Incorrect.PNG Undesired

 

Instead of ending up with the desired:

 

String Correct.PNGDesired

 

So, my question is, is there a way to change this behaviour so that the final string is displayed as above?

 

Cheers for looking and thanks in advance.

 

Mitch

 

 

0 Kudos
Message 1 of 22
(3,594 Views)

If you have a comma separated file you should not use commas within the values. Simple as that.

With date and time it is desired that they are separated into 2 columns?

I would recommend switching either the column delimiter to a semicolon (or something else) or avoid using commas within a column.

 

0 Kudos
Message 2 of 22
(3,580 Views)

Hi dan_u

 

Problem is this is code I've inherited that I want to modify slightly and any change to the writing method will incur problems elsewhere.

 

Yes its desired that the date and time is separate and I actually prefer it that way to be honest.

 

Switching to an alternative delimiter may end up being the only way to achieve what I want but I just wanted to know 100% that there is no special method to allow the commas to be shown like the special escape codes.

0 Kudos
Message 3 of 22
(3,567 Views)

Mitch,

 

escaping the comma could be an option but that would depend on the application accessing the csv file. I'm not aware of a general way.

 

0 Kudos
Message 4 of 22
(3,556 Views)

You have left out the code that you use to write to the file and this will influence the result you get

 

When I want to do this I create an array of the data (1 item per column) and use Write to spreadsheet file.vi to get a tab delimited file which can then be opened in Excel using text to columns

 

Ken

0 Kudos
Message 5 of 22
(3,551 Views)

Write to spreadsheet file does have the Delimiter optional input (Default tab).  What are you using to write to file?


"Should be" isn't "Is" -Jay
0 Kudos
Message 6 of 22
(3,549 Views)
Solution
Accepted by topic author Mitch_Peplow

Hey Mitch_Peplow,


This will solve  your issue. The " " marks wont be displayed while viewing in excel. In case if this data is used for something else in labVIEW, you can just use the replace string function and replace " " with empty strings as there are no other " " used in the string. 

 

sample.PNG

 

Regards,
Nitzz

(Give Kudos To Good Answers, Mark it as a Solution If your Problem was Solved :smileywink:)

Message 7 of 22
(3,540 Views)

LabVIEW both reads and writes to the file and apart from that we only open it in Microsoft Excel.

 

I left out the rest of the code as there is more processing going off before we write, I wanted to keep it simple.

 

The code is currenty using the Write to Text File.

 

 

0 Kudos
Message 8 of 22
(3,537 Views)

@Mitch_Peplow wrote:

LabVIEW both reads and writes to the file and apart from that we only open it in Microsoft Excel.

 

 

The code is currenty using the Write to Text File.

 

 


Then the fix is easy- use write to spreadsheet to format the darn text into a spreadsheet that you only open in excel and read from spreadsheet to read the spreadsheet


"Should be" isn't "Is" -Jay
0 Kudos
Message 9 of 22
(3,513 Views)

Pure and simple, if you have a comma separated values, you can't have commas in the data.  I would recommend changing the last string to use a tab instead of a comma.  A semicolon would be my second choice.  But why not just have 2 additional columns?  That would be the easiest.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 22
(3,512 Views)