LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing two arrays to a Excel Spreadsheet

Guru's

I am trying to take information from two arrays and write them to a spreadsheet. One array generates the headers information for the columns, the other array is a random number generator. The number of columns and rows are input from the front panel. The first column of the chart is time at some multiple (interval) input from the front panel

The problem I am having is timing the data out of the loop at the same time so they write together. One loop writes first and the other is left out. The data is going out to an excel spreadsheet. The data is correct for the headers and the columns, but won't write together.

I have only been using LabView for six weeks and have spent a good portion of this weekend working on this problem.

Attached are screen shots and the .vi of the problem. Explanations of each loop are writen in the block diagram.

Thank you for your time and help!!

Newbie2
Download All
0 Kudos
Message 1 of 9
(3,628 Views)

First let's talk about the code flaws:

  1. Placing a text decoration over a path constant does not turn it into a valid path constant.
  2. All your controls belong outside the loop, because it would be really bad if they could change during running of the loop. This is also less work, because LabVIEW does not need to re-inspect the control during each iteration.
  3. Your while loop should be a FOR loop because the number of iteration can be calculated before the loop starts. This eliminates checking for termination.
  4. You are not writing any excel files. You are just writing an ASCII table, but you possibly force excel to open it via a fake file extension. (this might be OK, but make sure to NEVER save it later as excel or the file structure would change dramatically).
  5. "# of rows" and "# of machines" should be integers (blue).
  6. Don't be afraid to brance a wire. You don't need any local variables if you do so.

To determine the order in which the segments are written to the file can be determined by dataflow if you wire it correctly. Wire the path to the write function that needs to write first. Then use the path output of this function and wire it to the next instance. Now the second instance must wait until the first one is finished.

(Currently you are branching the path wire, and the execution order is random!)

Message 2 of 9
(3,627 Views)
Here's a quick draft (LV 8.2) how you could simplify your code. Notice the correct dataflow for the file writes.
 
You were doing things way too convoluted. 🙂
Message 3 of 9
(3,618 Views)
Thanks for your suggestions.

I'll start making the changes you suggested and see how it goes.

Thank you!
0 Kudos
Message 4 of 9
(3,614 Views)
Greetings!

I am impressed with how quick you replied back with that .vi. Experience!! Is there a way that the ascii file can still be created with the header and numbers IF the table was removed from the front panel.

I tried to remove the table and column hdr property and it goes back to the earlier issue with timing.

Thanks for your help!
0 Kudos
Message 5 of 9
(3,602 Views)
I got it modified and running!! Thanks for your help.
0 Kudos
Message 6 of 9
(3,592 Views)

An indicator never changes the underlying data or program structure. You don't need it to write the file. (Still, it's good to have for troubleshooting until you know the data is arranged correctly, etc.. 🙂

I made it to replace your mix of a string array and 2D DBL array indicator, which is only confusing. In the final code, you don't need any indicators.

(You must have deleted an extra wire somewhere. 🐵

0 Kudos
Message 7 of 9
(3,588 Views)

Thanks everyone for providing suggestions and comments. The is post helped me a lot.

joe

0 Kudos
Message 8 of 9
(2,987 Views)

@joe5213 wrote:

Thanks everyone for providing suggestions and comments. The is post helped me a lot.

joe


Give thanks by giving kudos, it doesn't cost anything I promise.

Message 9 of 9
(2,977 Views)