Writing to the text file in the same line (without starting a new line)
In my projects sometime I need to write a 2D array in the same line into the text file (see the figure below).
We know that LabVIEW can write 2D arrays directly to the text file using “Array to Spreadsheet String.vi” or “Write to Spreadsheet File.vi”. But when we want to convert it to a single line it is not straight forward. We can convert the 2D array into 1D array before writing using “Reshape Array”. I don’t like this method, which is inefficient in term of space and time. Alternatively, we can write the 2D array row by row using a for loop. But LabVIEW just automatically start a new line for each iteration . The method I used is simple, but took me a while to come up with. I set the file position (“Set File Position”) each time when a row is writen, as shown below
The file position is set at the end and the offset is changed to -2 to delete the carriage symbol. A tab string is added afterwards to keep format the same. This program does the job without converting the 2D array. You can add “Transpose 2D Array” for the 2D array if needed.