LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

run for loop once to build array

I have a VI that i want to use to add a row of a 1d array to a 2d array. everytime i run the VI it writes over the previous data. is there any way i can add a new row to the 2d array every time it runs.

Thanks
Mike
0 Kudos
Message 1 of 5
(3,302 Views)
Hello
Just a couple things: if want to add array, do not initialize the array every time you run the vi.
ans use "build array" to build arrays.
See attache your vi corrected
Alipio
---------------------------------------------------------
"Qod natura non dat, Salmantica non praestat"
---------------------------------------------------------
0 Kudos
Message 2 of 5
(3,300 Views)
Dear Mike,

replace the "Insert into array" function by a "Build array" function to add the row at the end of the existing 2d array.

If you want to insert the row at the top of the array you must use "Insert into array" function. The problem with your code is that you always initialize the shift register with an empty 2d array each time you run the VI. The problem is that if you delete the initialzing array the shift register switches from 2d array of string into 1d array of string and breaks the VI.

The only solution I see is to replace the shift register with some global storage. You have three methods: Global variable, LV2 style global or single element queue which was discussed here some days ago.
Waldemar

Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
Don't forget to give Kudos to good answers and/or questions
0 Kudos
Message 3 of 5
(3,291 Views)
I found the solution:

1: Create a case structure around your code in the for loop.
2: Switch to the FALSE case and copy the initializing constant into the case structure and wire it to the tunnel.
3: create a boolean constant TRUE and wire it to the Case selector.
4: Delete the initializing constant.

The shift register will stay as a 2d array of string, comming out from the FALSE case. The FALSE case will never be executed. If you replace this boolean constant by a control you can empty the array. Flip the cases and name it Init.
Waldemar

Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
Don't forget to give Kudos to good answers and/or questions
0 Kudos
Message 4 of 5
(3,287 Views)
For your other thread concerning the while loop:

to run a while loop once create a boolean constant and wire it to the loop condition terminal. Set the boolean to TRUE and the condition to "Stop if True" (the default when you create a while loop).

An experienced programmer would choose a solution with a while loop instead of a for loop. If the data would come into such a construct through a tunnel and the data is an array the for loop will not execute when the array is empty but the while loop will.

Your changed code in LV 7.1.1
Waldemar

Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
Don't forget to give Kudos to good answers and/or questions
Message 5 of 5
(3,278 Views)