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: 

Count when ever boolean is true /populate array

Solved!
Go to solution

Hello Everyone,

 

I believe this is a fairly easy task , but for some reason I am unable to make it work.

 

The problem is explained below:

 I have 3 slider which gives either 0,1,2. I have a "next" button which is basically a boolean button. Every time I click the "next" button, I want the values from the 3 slider ( 0,1,2) to go into an array. The index of the array is decided by how many times I have clicked the "Next" button. Basically if I click next the fist time, the values should go to the 0th row, when I click the second time , it should go to the first row, etc.. This should keep happening till I click the Stop button, when it should display the populated array with its corresponding index to me.

 

I tried using a program for a Boolean count which continuously keeps counting how many times I pressed the next button. But that loop goes on infinitely. Otherwise, it starts counting from 0. I am not sure how to make it alright.

 

The program is shown here with comments.

 

Please help

Gayatri

 

0 Kudos
Message 1 of 10
(3,794 Views)
Solution
Accepted by topic author GV8

You really should use an event structure.  Keep the array in a shift register and just use Build Array to add to it each time the Next Value Change event happens.  Have another event for the stop button.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 10
(3,784 Views)

As a first step try using a single outer loop and no local variables. This is a very simple problem!

 

Your diagram comment "This loop goes into an infinite loop as the stop is always false" already gives you a clue that the current code is all wrong. Did you write that?

 

Are you familiar with the event structure? Also, your "next" button should be latch action.

 

If it could execute, your outer code currently tries to build a 1D array with exactly three new elements with every call. I imagine you want to generate a 2D array with columns and n rows, for example. The array needs to be kept in a shif register so it remembers the earlier additions.

 

See how far you get. I would recommend completing some easy tutorials first.

Message 3 of 10
(3,782 Views)

@crossrulz wrote:

You really should use an event structure.  ....


I would recommend to place the array indicator before the event structure. Currently it shows stale values on the second run until the button is pressed at least once.

0 Kudos
Message 4 of 10
(3,776 Views)

@altenbach wrote:

@crossrulz wrote:

You really should use an event structure.  ....


I would recommend to place the array indicator before the event structure. Currently it shows stale values on the second run until the button is pressed at least once.


You're probably right.  But you can't expect too much from an example put together in 30 seconds.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 5 of 10
(3,773 Views)

@crossrulz wrote:
You're probably right.  But you can't expect too much from an example put together in 30 seconds.

Sorry, it was just a side comment. It is possible that you had set the execution option to "clear indicators when called", which would make the move unecessary, but things like that don't survive in a snippet. 😉

 

II would have let the guy marinate a little bit more before giving a turnkey solution. Smelled like homework... 😄 Maybe I am wrong....

0 Kudos
Message 6 of 10
(3,764 Views)

Thanks a lot

0 Kudos
Message 7 of 10
(3,743 Views)

Hello Altenbach,

 

Thanks for your comments. I would ike to mention here that even though this question was quite basic... it doesnt really mean it is for home work and I am trying to get answers from forums. I have already fininshed my PhD, and it is just that I am a little rustic with LabVIEW having last done it, 6 years ago with a very old version. So at this point I am re-learning LabVIEW.

 

I  do appreciate your comments though.

 

Thank you

G

0 Kudos
Message 8 of 10
(3,729 Views)

GV8 wrote:I would ike to mention here that even though this question was quite basic... it doesnt really mean it is for home work and I am trying to get answers from forums.

Take no offense.  We get a lot of students on this site asking for us to do their work instead of actually putting forth some effort.  It is that time of year where we really get bombarded (end of semester).  I saw at least some effort in your attempt, so I gave a solution.  Without a VI to show where you were, I would have suspected someone looking for a handout as well.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 9 of 10
(3,716 Views)

No offense taken. And I really appreciate the help which was given by both of you guys... 🙂

 

 

0 Kudos
Message 10 of 10
(3,708 Views)