09-16-2021 02:43 AM
HI everyone, I am trying to save some values in an array which is being formed by auto indexing of the for loop .However I would like to run the for loop only on the button press named "next" and append this value to the same array . Could anyone help me with implementing this logic. Right now when I press the next button , nothing happens and I only get one value in the array.I am attaching my code in the picture and the VI in the file.
Thanks 🙂
Solved! Go to Solution.
09-16-2021 02:55 AM
It only returns one value because you set it that way...
You made your event to trigger when you click "Start" button, so you'd have to simultaneously click the Start and the Next button to do what you want, otherwise the loops already executes when you click the next button.
Why don't you just put the loop into another event, a next button value change event?
I'm not really sure what you want to do here to give better advice, other than creating another event.
09-16-2021 03:09 AM - edited 09-16-2021 03:11 AM
Hi shahshery,
@shahshery wrote:
I am trying to save some values in an array which is being formed by auto indexing of the for loop .However I would like to run the for loop only on the button press named "next" and append this value to the same array . Could anyone help me with implementing this logic. Right now when I press the next button , nothing happens and I only get one value in the array.
Your VI design is highly flawed! Do you learned the basics of event structures?
I suggest to implement it this way:
09-16-2021 03:15 AM
Thanks for your response:) With the start button and the outer event loop I'm just trying to run the program when the start button is pressed and stop it when the stop button is pressed inside the VI rather than using the abort execution button.With the next button I just want to run the for loop for 1 iteration then stop until i press the next button again . This should happen each time when the next button is pressed until the loop has run N times which is predefined in the control named "number of devices".After all the loop has run N times , all the values that were generated in each iteration should be saved in an array.If you could help me with implementing this logic I'd be really grateful.
09-16-2021 03:28 AM
You don't need start button to do that, the stop button was correct tho.
GerdW's code does exactly that, with the exception of checking if Next was pressed N times already.
His code executes the event each time Next button is pressed, so you get # of data points for each "device".
09-16-2021 03:35 AM
Hi shahshery,
@shahshery wrote:
With the next button I just want to run the for loop for 1 iteration then stop until i press the next button again .
My code does exactly this: running the code inside your FOR loop exactly once and then wait until you press "next" the next time…
@shahshery wrote:
This should happen each time when the next button is pressed until the loop has run N times which is predefined in the control named "number of devices".
Then you should disable the "next" button once the array in the shift register contains the number of required elements: check for ">= number of devices"…
@shahshery wrote:
all the values that were generated in each iteration should be saved in an array.
The values are "saved in an array" which is hold in this shift register. So this requirement also is fulfilled.
09-16-2021 03:37 AM
Dear GerdW,
Thanks for your help.I am not actually a programmer but just a student trying to solve a basic problem that explains my mistakes 😄 I'll try your program and get back to you if I need further help 🙂
09-16-2021 03:53 AM
Thanks a lot GerdW , for now your code works for me 🙂