LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing to an array in a Nested For Loop

In my VI, I am trying to read data from a INI file and write the data to my array. I can successfully read in data an populate my sequncer array and channel table. Though my event table is in a nested for loop and the data isn't being inserted. I can see the 1D array of the retrieved data flowing to the insert function, but is never passed through to the table. If anyone knows what is going on, please let me know. I've included a sample INI file.

Download All
0 Kudos
Message 1 of 11
(3,996 Views)

I can't look at your code but a couple things you can look for yourself:

For loops in LV can execute 0 times. To determine the number of iterations for a FOR loop LV looks at the value wired to the N node, and size of all arrays that are auto-indexing at the loop border and picks the smallest number as the number of iterations for the loop. So if you have a FOR loop that appears not to execute, it's probibly because you are unintentionally telling it to execute 0 times.

Mike...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 11
(3,986 Views)
Can I make a suggestion or two?  Your code is difficult to read because it is so large.  Most of the code is repetitive.  You could benefit greatly by using arrays for all the config vi inputs (like Title, Channel, etc.), wire the array to a For loop with indexing enabled, use just one Read Config File vi inside the loop, and wire the output of the Read to the For loop edge with indexing enabled.  Your output would be an array of all the values in the same order as the input array of key names.  This would greatly reduce the size of your block diagram and make it much easier to follow.  Any time you have to scroll up and down and right and left to see all of the block diagram, your diagram is too large.  Try reducing it in size and then maybe one of us would be more willing and able to help you with your problem.
- tbob

Inventor of the WORM Global
0 Kudos
Message 3 of 11
(3,976 Views)
A few additional suggestions:
  • Do the opening/closing of the config file outside the loops. By my count you were opening/closing the file 321 times. You only need to open/close it once.
  • You were using the Reshape Array to reshape a 1D array into... a 1D array. This is pointless.
  • You do not need to use the Insert Into Array function. Use auto-indexing to get your 2D arrays automatically.
  • It's not clear how the "events" are supposed to be parsed out. It seems that you were reading up to 10 events, whether or not they were defined in the config file, but you had a "Events=1" line in the config file to define how many events.
  • You may benefit by making the config file an XML file since that will give you far more structure to it.
0 Kudos
Message 4 of 11
(3,965 Views)

Thanks for the input! I'll move my open and close file functions outside the loop! I'll have to research the auto indexing feature that you're talking about. The only reason I reshaped the array, was to change the 1D array from a vertical to a horizontal array so I could insert it into my table. Though if I can figure out the auto-indexing I'll get rid of it. I already know that I can't change the config file format. So I'm stuck with INI.

I did find what was wrong. I didn't initialize the array. The channel setup table was fine without being initialized but the event setup wasn't. So I just initialized the first two rows to an empty string in the INIT Case. However, now my event setup table keeps writing data to row 110.  Is the max 2D array size 110x10? Or do you know what is going on? 

Download All
0 Kudos
Message 5 of 11
(3,959 Views)

Here is an example of auto indexing and For Loops.  This can be used with While Loops too.  Now can you see how much simpler your block diagram could be?

Somehow the comment got cut off at the top.  It says that the indexing feature extracts the elements out of the array one at a time and uses them.

Message Edited by tbob on 05-08-2007 12:15 PM

- tbob

Inventor of the WORM Global
0 Kudos
Message 6 of 11
(3,955 Views)
Regarding the reshaping: I saw the comment you had in your code, but a 1D array has no "horizontal" or "vertical" in LabVIEW. It's simply a 1D array. It becomes a row or column in a 2D array based on how you're addressing the 2D array.
0 Kudos
Message 7 of 11
(3,949 Views)
Thanks guys for your help, my code looks a lot cleaner. I'm having trouble with placing the data into my Event setup table. I do not know how to index the data coming out of my nested for loops. I either need to index the data coming out of the 10 iteration loop and write it to the table; or grab the 3D array data coming out of the 32 iteration loop break it up and write it to the table. But I'm not sure how to do either of these. I show my feabile attempts to work with the 2D array in my code. If you know any solutions, please let me know.
Download All
0 Kudos
Message 8 of 11
(3,928 Views)
I figured it out!
0 Kudos
Message 9 of 11
(3,926 Views)
Remarkable improvement in code readability.  You learn quickly.
- tbob

Inventor of the WORM Global
0 Kudos
Message 10 of 11
(3,905 Views)