From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Insert Array In Case Structure Does Not Restart

Solved!
Go to solution

This VI is going to be part of a larger program. It's fairly simply, as it is initializing and array, passing that array into a while loop and into a case structure, where, in the True case, the Insert Into Array VI adds the loop count to the index equal to the loop count. I have also made it so that when the case is false, the array is wired straight through to the shift register. The problem is, when I use a button starting on the True case, then switch to the False case, and then go back to the True case, the Insert Into Array VI no longer inserts values into the Array. How can I fix this? I have attached my code below.

0 Kudos
Message 1 of 4
(825 Views)

I cannot see your code because I don't have LabVIEW 2021. Consider "save for previous".

 

To append data to an existing array you would use "built array". I assume you are using a shift register to hold the array between iterations, else you are starting with the same old short array again in the next iteration, right? Where do you get the insert position from? hopefully not [i], because that will be outside the valid elements once you skip an insertion.

 

(Using insert into array is useful if you need to insert an element somewhere in the middle, moving all higher element up one slot.)

0 Kudos
Message 2 of 4
(822 Views)

I have attached a version saved for 8.0 here. Yes, you  are right that I am using a shift register to hold the array between iterations and it seems that I am inserting at the position [i]. Would a solution be just to append 0's to the array in the false case, or is there a cleaner solution with another function?

 

Thanks.

0 Kudos
Message 3 of 4
(813 Views)
Solution
Accepted by topic author hulksmash88

You need to start with the basic tutorials!

 

  • Why is the array orange if you are only inserting integers?
  • Why are you spinning the loop millions of times per second whenever the boolean is false? On the next true, [i] will be in the millions and outside the range of valid elements. (If you want to use "insert into array", you need to keep track of an integer that only increment when the button is true, right? This requires another shift register or measuring the array size. None of that is needed with "built array"!)
  • Try something like this instead.

 

altenbach_0-1639019641870.png

 

0 Kudos
Message 4 of 4
(808 Views)