LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problems in writing to text file using array to spread sheet

Hi...

In my application ,i have an array that i have to write to text file.so before writing to text file,am converting the array to spread sheet format,

using array to spread sheet conversion.

 

The array i am converting is a 2D array.Suppose the array contains 6 elements. as follows

 

2009-02-23 16:32:00+04.210-00.002-00.002-00.002+00.000-00.004+00.002-00.002
2009-02-23 16:31:00+04.216-00.002-00.004+00.002-00.004-00.002-00.002+00.002
2009-02-23 16:29:59+04.214-00.002-00.002-00.002+00.000+00.002-00.002-00.004
2009-02-23 16:28:58+04.216-00.002-00.002+00.000-00.002-00.002+00.000-00.002
2009-02-23 16:27:58+04.210-00.002-00.002-00.002+00.000-00.004-00.002+00.000
2009-02-23 16:26:57+04.210-00.002-00.002-00.002-00.002-00.002-00.002-00.002
2009-02-23 16:25:56+04.210-00.002-00.002-00.002-00.002-00.002-00.005-00.002
2009-02-23 16:24:56+04.216-00.002-00.002-00.002-00.002+00.000-00.004-00.002.

What i have to do is,have to delete the first element from the array and convert to spread sheet string and then to write to the text file.

 

The result of array to spread sheet conversion is correct..it resu,lt me as follows..which is correct...

2009-02-23 16:31:00+04.216-00.002-00.004+00.002-00.004-00.002-00.002+00.002
2009-02-23 16:29:59+04.214-00.002-00.002-00.002+00.000+00.002-00.002-00.004
2009-02-23 16:28:58+04.216-00.002-00.002+00.000-00.002-00.002+00.000-00.002
2009-02-23 16:27:58+04.210-00.002-00.002-00.002+00.000-00.004-00.002+00.000
2009-02-23 16:26:57+04.210-00.002-00.002-00.002-00.002-00.002-00.002-00.002
2009-02-23 16:25:56+04.210-00.002-00.002-00.002-00.002-00.002-00.005-00.002
2009-02-23 16:24:56+04.216-00.002-00.002-00.002-00.002+00.000-00.004-00.002

 

But after writing to text file,the only thing being written is the following

2009-02-23 16:24:56+04.216-00.002-00.002-00.002-00.002+00.000-00.004-00.002

 

All other data lost....I cudnt find where am going wrong...

Pls guide me on this.

Am attaching a sample code as attachment...

Thanks in advance

 

0 Kudos
Message 1 of 8
(5,650 Views)

Hello

 

this is because, whenever you are opening the file, index will be 0.. & then you write anything, it will overwrite the previous data ... 

 

For  your requirement, you have to use "Write to Spreadsheet String.vi".. please see the attachment.

 

 

Thanks & Regards,
Rajan
Message 2 of 8
(5,636 Views)

HI

First close the connection after writing to file, then open the new connection and read the file.

Hope this helps

Regards

Santosh

0 Kudos
Message 3 of 8
(5,632 Views)

Hi Rajan, 

 

Thanks for ur reply.

 

I cud only find write to spreadsheet file.vi...and using that cant input 2d array of string.

 

I was unable to locate write to spreadsheetstring.vi..I am using labview 8.0.

 

Am attaching my code after changing...

 

Please guide me on this.

 

Thanks again...

Message Edited by user_1 on 02-23-2009 07:31 PM
0 Kudos
Message 4 of 8
(5,590 Views)

Hello

 

I need not read & close the ref ... just create the file first .. & then keep on appending the data to it .. If you can upload the VI, it would be easy for me.. 

Thanks & Regards,
Rajan
0 Kudos
Message 5 of 8
(5,570 Views)
Hi, Opening and closing the reference to a file multiple times in a loop is a terrible waste of resource. Either open before, continuously write, then close after the loop; or compile all your data in an array and write it all at once through a separate file sequence after the loop. Not only are both better development practice, they would also solve your underlying dilemma. Best Regards, Joshua de la Llana NI Applications Engineer
0 Kudos
Message 6 of 8
(5,532 Views)

Hi user_1,

 

To my understanding, Write to Spreadsheet.vi in LabVIEW 8.0 can only write 1D/2D Numeric Array. Hence, you may want to consider using Array to Spreadsheet method again.

 

Let me summarise your problem. Your problem is when you read back from your read (as shown in array to spreadsheet.jpg), you only manage to read 1 element in your array. The rest of the 6-7 elements are missing. Please correct me if I am wrong.

 

The reason to your problem is because of the write to file pointer. For the 1st time, you write 8 elements (there is 8 rows in your 1st 2D array in your post). The 2nd time, you write 7 elements (7 rows in your 2nd 2D array). Because you use 'open', the 2nd time you write will replace row1-7 data in your text file. The pointer now rest at the end of row 7. So when you read after that, you will read row 8 (which is element 8 in your 1st 2D array).

 

To solve your problem, you should modify your vi to something similar to the picture attached below. This will reset the pointer to the start of the file before reading the data in the file. By doing this way, you will read all the datas in the file.

 

This problem do not occurs if you only open, read and close file (not open, write, read, close file). The pointer is reset to the start of the file when you use Open File function.

 

Hope this solve your problem.

 

Regards

Lee

Message 7 of 8
(5,513 Views)

Hi ...

 

I cud fix the thing by changing theVI," Write to Spreadsheet file.vi" according to my need.Thanks for all helps!!!!

0 Kudos
Message 8 of 8
(5,480 Views)