LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple Arrays to Spreadsheet

Solved!
Go to solution

You have your write VI outside the loop and the data array is not being auto-indexed so only the last iteration of the for loop is contained in the array.  You need to put the case structure inside the loop.  However, it will still force a new file to be created since you're changing the file name by updating the time each iteration.  Add your time stamp to the data instead.

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019
0 Kudos
Message 11 of 21
(2,379 Views)

Hi,

 

I've modified the vi, and it is working now. Also, I've added the header lines portion (i.e. "channel #" and "x y z" from my example), and now the question is how do I enter the string each iteration, and how can I name the file after the vi is done with the iterations?

0 Kudos
Message 12 of 21
(2,370 Views)

I think you're at the level where it's time to stop using the 'Array to Spreadsheet.vi'.  It's polymorphic so it can accept numbers but, of course, since your end product is a text file you're actually dealing with text.  What you need to do now is learn to format your own strings properly so that you can concatenate them together with the right delimiters and then write it to your file. 

 

The first step is to open the Write to Spreadsheet VI and see what's inside.  You will see the LV primitives that open the file, set the insertion point, write the data, and then close the file. 

 

First off, you should note that opening and closing the file on every iteration is inefficient.  You should open your file before the main part of your code runs (the loop), write to the open file during the loop, and then close the file after the loop ends.  Inside the loop, use the various format string VIs ( 'Format into String' and 'Array to Spreadsheet String' are your friends!) to create a complete data string out of all the information you want to write at one time (run header, timestamp, or whatever, PLUS the data array).  Check out the shipping example for more info on this.

 

BTW, this is only one way to store data.  Remember LabVIEW has built-in data logging of several types.  The TDMS format is the best (IMHO) as it is becoming an industry standard and the files can be opened in Excel directly using the TDMS plug-in (free to dowload).  Check out the examples for more info on that too.

 

As far as naming the file after the test is finished?  You're better off naming it BEFORE the test starts.  Since you're writing to the file during the test you have to name it something first.  You could always rename (File>Advanced>Move.vi) it at the end based on operator input.

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019
0 Kudos
Message 13 of 21
(2,347 Views)

A quick example:

24062i002A1F6D6E2E46C5

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019
0 Kudos
Message 14 of 21
(2,342 Views)

Hi NIquist,

 

Thank you for the explanation and example/references.

You are correct, I've tried to avoid it for a long time but it's time to leave to comfort of built in vi's....

As far as the vi itself, I'll stick to text files for now since it's sufficient for the functional spec, and I'll probably convert it to TDMS in a week or so after reading about it in depth. In my case, the file name comes, in part, from the original data file, so I must create/name the file in/after the loop, or I can get the path before entering the loop but that will create redundancy....  

I've tried to reconstruct your example, what is the arrow that connects to Concatenate Strings Function? 

 

0 Kudos
Message 15 of 21
(2,330 Views)

That's a TAB constant (Strings palette).  You can also use a comma (for a Comma Separated Values file) but the tab separated files are more popular now.  Especially when you must deal with european files which use the comma for a decimal point!

 

EDIT:  One thing I should make clear:  The Format into String VI expands to accept multiple inputs of different datatypes.  You modify the format string (on top) to tell the function what to expect (e.g. %d is decimal, %s is string, %.5f is floating point truncated to 5 digits, etc.)  These function are very powerful string manipulators once you learn the syntax.  It's much like the regular expression functions in languages like C++ and JAVA.  They go a long way in helping deal with strings in LabVIEW and so are well worth learning.

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019
Message 16 of 21
(2,323 Views)

I think it's almost there, I just a have a couple of formatting issues:

how do you insert data to a new line?

because right now it writes all the data properly, but it the lines are messed up. 

Note: in the file-- what I should get, it should be nzl # and then all the data in one row for every row).

Download All
0 Kudos
Message 17 of 21
(2,310 Views)

You can do this easily with the format string itself just by adding escape characters just like in any other language. 

For example:  Hello\sWorld!\s\sTAB2\tTAB2\tNEWLINE1\nNEWLINE2\n\n\n\nNow I'm down here... %f\t %d\n\n %s  will print:

 

Hello World!  TAB2    TAB2    NEWLINE1
NEWLINE2



Now I'm down here... 1.234500     555

 A string

 

This is with 1.2345 wired to the DBL input, 555 wired to the I32, and "A string" wired to the string input.  You have to match up the '%'s with the appropriate datatype but you can put anything else in the format string you want (including standard escape characters) and it will become part of the output string.

 

HINT: when you play with this type of thing, right click your string indicator and select "code's display".  That way you can see the escape characters embedded in you resultant string.

 

EDIT:  You can always do the same thing manually by concatenating string constants together.  This is just a convenient way to do it.  Also, you can right-click the 'Format into String VI' and select 'edit format string' to help you make it even easier.

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019
Message 18 of 21
(2,288 Views)

Thank you so much for your help, this whole area of LV is foreign to me. 

" ....format string itself..." this sentence made me try to do it because it is more convenient as you said. 

Then I've found Format Into File Function, which is basically the same thing but simpler perhaps (more built in, less user defined)?!

And I think I'll use it, it gives me the output right away....

I'm going to do some reading about this whole thing and TDMS this weekend.

I really appreciate your help & explanations (and hints:-).

 

 

 

 

 

Download All
0 Kudos
Message 19 of 21
(2,278 Views)

Ok, I really dont know what's wrong with it.It works nice with floating numbers (like in my example), but when I pass the array, it still does the same thing it did before. Does LV have a row space limit of something? I really don't know what can be wrong with it now.

Download All
0 Kudos
Message 20 of 21
(2,264 Views)