From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Write character to file

I'm using a For Loop to process a big string. In the loop, I have a
Write Character to File icon to save data into spread sheet format. The
loop runs 40 cycles, so it take many seconds to finish. I know the main
time is used on the saving files, I tried to put the Write Character to
File icon out of the For Loop, then there will be a type mismatch. Any
one can give me some suggestion about what I should do?

Thanks in advance,

Guangde Wang
0 Kudos
Message 1 of 4
(2,610 Views)
The Write Characters to File function does an open and close file every time it is called. Instead, what you could do is open the file at the beginning and then use Write File+ (string). The other option would be to convert the string into array elements and then use Write to Spreadsheet File.vi only once.
0 Kudos
Message 2 of 4
(2,610 Views)
Dear Dennis,

Thank you for responding to my message. I'm interested in both of the two
ways, but I have problem with both of them.

1. There is no open file or close file function, so I don't know how to
open a file and keep it open until I close it,

2. Because the Write Charaters to File is in a For Loop, I can not use
Contenate Strings function to connect them. But if I wire the output out
of the For Loop, then there is a data type mismatch.

So please advice in some details about how we can do it.

Thank you,

Guangde

Dennis Knutson wrote:

> The Write Characters to File function does an open and close file
> every time it is called. Instead, what you could do is open the file
> at the beginning and then use Write File+ (string). The other option
> wou
ld be to convert the string into array elements and then use Write
> to Spreadsheet File.vi only once.
0 Kudos
Message 3 of 4
(2,610 Views)
There are both open and close functions in the File I/O pallette. Open is under the advanced functions I think. And you can certainly concatenate strings inside of a for loop. Wire the concatenated string to a shift register as you go through the loop. The reason you get a type mismatch out of the for loop is that the for loop creates an array out by default. If you use the output of the shift register, you won't have the problem.
0 Kudos
Message 4 of 4
(2,610 Views)