LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

clear array out of for loop

Solved!
Go to solution

Hi everybody,

 

I have a question about clearing the array history. It seems simple but I am really confused...

 

As the example attached below, I built an array inside a while loop and a for loop. After totally finishing running the program once, when I run it a second time, it seems that the array has memory of the last time, i.e. the array size does not start from 0, and the old number from last time appears, even through it is initialized out of the for loop.

 

How could I make it start from empty everytime when I restart the array?

 

Need your help. Thanks a lot. : )

0 Kudos
Message 1 of 13
(17,777 Views)

Hi cun,

 

initialize the shift register with an empty array constant (right-click shift register input node -> create constant)!

There are surely example coming with LabVIEW showing exactly that programming scheme...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 13
(17,770 Views)

More specifically, you are initializing the indicator, but the data is actually retained in the shift register. Once you initialize the shift register, the display will show the new data, so there is no need to reninit the indicator.

 

What is the purpose of the outer FOR loop? It does not seem to add any functionality to the program. If you would remove it, nothing would change.

0 Kudos
Message 3 of 13
(17,764 Views)

Well, this is not a formal program. I just scrabed a part from my initial program, since it is clear to explain my question...

0 Kudos
Message 4 of 13
(17,754 Views)

Thanks for your help, but I think I should put the constant outside of the while loop, right? Because I don't want to initialize it until finish running the whole program, but when I do that, it doesn't work well... How should I change it?

0 Kudos
Message 5 of 13
(17,750 Views)

@cun wrote:

Thanks for your help, but I think I should put the constant outside of the while loop, right? Because I don't want to initialize it until finish running the whole program, but when I do that, it doesn't work well... How should I change it?


I can't see the code, but I imagine auto-indexing is on the while loop tunnel.  Disable the auto-indexing on the while loop tunnel and it should go where you need it to go.  🙂

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 13
(17,746 Views)

@cun wrote:

Thanks for your help, but I think I should put the constant outside of the while loop, right? Because I don't want to initialize it until finish running the whole program, but when I do that, it doesn't work well... How should I change it?


Of course the constant goes outside the loop. It should be wired to the left shift register from outside the loop to initialize it. This will initialize when the loop starts.

 

There is nothing to initialize when the program finishes. Why do you think you need that?

 

"it doesn't work well" is not a useful description. What happens? What do you expect to happen? On a scale from 1-10, how "well" does it work?

0 Kudos
Message 7 of 13
(17,724 Views)

I did this and initialized the array out of the for loop, but it also initialized the array for the while loop.: (

 

What I expect is to initialize the array after finishing the for loop but keeping all the data for every while loop. i.e. When I click the stop button once, the array grows continuously, but when I click it the second time to finish the for loop and stop the whole program, the array will be cleared and start again for the next time run. Thanks.

0 Kudos
Message 8 of 13
(17,717 Views)

I found that if I don't initialize after finishing the whole program, the array will begin from the last time's result... That is what confused me...

0 Kudos
Message 9 of 13
(17,713 Views)
Solution
Accepted by topic author cun

You should also have a shift regsiter in the FOR loop. This will keep the data for the duration of the program, but clear it at the beginning of the next run.

 

0 Kudos
Message 10 of 13
(17,708 Views)