LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

writing Array & String to text file

wanted to write numbers and string to text file .   i used "write to spreadsheet file".
i can write contents of array to file.
i already have "write to spreadsheet worked" for below
1 1 1 1
2 2 2 2
 
Now i want to add "some string" after the arrays element is written in file
What i am trying to get is
1 1 1 1
Testing
2 2 2 2
 
i tried by opening the same *.txt file and then "Setting File position to end" 
and then "writing to text file"
why am i doing all this is "write to spreadsheet file" doesnt take strings !!!
problem getting is "write to test file" overwrites Previous contents
Attached is the Snap Shot
 
Suggest how to get this going !! Thanks
Praveen

 
0 Kudos
Message 1 of 7
(3,963 Views)
Use DATAFLOW!. Wire the error out and New File Path from the Write to Spreadsheat to the Open/Create/Replace File.
0 Kudos
Message 2 of 7
(3,952 Views)
Can you explain little bit more in breif. Culdnt find still easier way to club string and Int then write to txt file
Still i have done writing of array to file using "write to spreadsheet file"
 
Praveen
0 Kudos
Message 3 of 7
(3,918 Views)
Why all that song and dance? After all, a file is nothing more than a seqence of bytes. For example a spreadsheet is just a series of formatted numbers with items typically separated with tabs and rows separated with newline characters.
 
Why don't you compose exactly what you want in memory (e.g. using "array to spreasheet string", "concatenate strings", formatting operations, etc.) and write the resulting plain string to a file using "write text file" in one swoop? You can even send it to a suitably sized string indicator first to make sure it all looks right. 🙂
0 Kudos
Message 4 of 7
(3,907 Views)

With the wire tool, connect the output terminal called 'New File Path' of Write to Spreadsheet File to the input terminal called 'file path' of Open/Create/Replace File. This means you have to delete the file constant you have now. The shipping version of Write to Spreadsheet File has no error out connection. I've been using my own with a connection for so long that I forgot that. That doesn't matter as long as you wire the file paths together. That's enough to enforce dataflow.

Understanding what dataflow is, how it works, and when to use or not use it is essential to understanding LabVIEW and writing programs with it. It is really the basic concept of LabVIEW. A function does not execute until the data for that function is present. Functions not connected by dataflow will execute in parallel (or attempt to anyway). Because you had no dataflow between the Write to Spreadsheet and the Write to Text File, you don't know which will actually execute first. Putting one funciton to left/right/top/bottom of another does not affect execution order at all.

Message 5 of 7
(3,902 Views)

ohh...not a real singer.:)

i have 2 dimentional array of integers,which i write to text file by "write to spreadsheet file"   (Example : 1.txt )

now lets say i want to insert a string to same file after each row contents (string should be in between row of integers) 

 i tried by writing string to 1.txt file with "write text file" ,but it is overwriting the previous contents i.e, 1st row elements written by "write to spreadsheet file

Praveen

 

 

 

 

 

 

 

 

 

0 Kudos
Message 6 of 7
(3,894 Views)


@praveen2 wrote:

i have 2 dimentional array of integers,which i write to text file by "write to spreadsheet file"   (Example : 1.txt )

now lets say i want to insert a string to same file after each row contents (string should be in between row of integers) 

 i tried by writing string to 1.txt file with "write text file" ,but it is overwriting the previous contents i.e, 1st row elements written by "write to spreadsheet file


Again, back to my statement that a file is just a long string of characters. A file has no concept of "lines". If you e.g. want to insert certain text after a certain line, you need to find the position of the n'th linefeed, read everything after that into a string buffer, then write your new line, followed by writing the content of the string buffer. If you insert N characters into a file at point A, all characters at higher indices need to be moved to make space.
That's why you should compose your desired final formatted string in memory. Writing the spreadsheet data first is useless because most of it will need to be moved later anyway. Don't make your life harder than needed. 😉 
0 Kudos
Message 7 of 7
(3,885 Views)