LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Write to array each time a button is pressed

Solved!
Go to solution

Hi

I wish to read from a radio buttons control when the 'Check Answer' button is pressed. I then wish to compare this value with a value in an array. If they are the same, I wish to update another array. The problem is, when I do this more than once the original array is wiped. I have attached my code below.

0 Kudos
Message 1 of 8
(4,335 Views)
Solution
Accepted by topic author Igorina

A shft register will be your friend.  It retains the value from the previous iteration and makes it available to the next one.  Look at the help.

 

You will want to change the Mechanical Action on your Check Answer button.

 

The data type for Select question should be an integer type.

 

You should have a Wait function in the loop.  No need for it to spin thousands or millions of times per second to respond to a human user.  Better, learn to use the Event Structure.

 

Lynn

0 Kudos
Message 2 of 8
(4,327 Views)

Thank you for your reply Lynn. I thought about using an event structure but you can't use shift registers with it. I'll try using the event structure in conjunction with a for/while loop and shift registers and see how I get on. Will post solution if it works.

 

Bryanna

0 Kudos
Message 3 of 8
(4,320 Views)

Your question is not clear anyway I would give my comments what I observed. You are initializing the array inside a while loop so this will initialize the array again and again resulting you will always get the array with elements false when you release the check answer button. So keep the initialize array outside the while loop and right click the tunnel and change that to a shift register. The whatever you perform wire it to the other end of the shift register then you will always have the recent data. If your problem is still not cleared explain your situation bit more.

-----

The best solution is the one you find it by yourself
0 Kudos
Message 4 of 8
(4,319 Views)

Thank you for your help Lynn, it guided me towards the solution which is attached below for anyone who is experiencing a similar problem.

 

Bryanna

0 Kudos
Message 5 of 8
(4,314 Views)

Braynna,

 

Now a few more things to make it even better.

 

Change the mechanical action of the Check Answer button to Latch When Released.  Pop up on the control from the front panel.  Mechanical Action is near the bottom of the menu.

 

Add an event case for the stop button value change event.  Put the terminal inside the event case and wire it to the termination terminal.  Then you do not need to press the Check Answer button an extra time to stop.

 

Wire the shift register straight through the cases where it is not used.  UseDefault if Unwired could cause you to lose all your data.

 

Remove the Timeout case.  It never executes, so why have it?

 

Lynn

0 Kudos
Message 6 of 8
(4,310 Views)

You are on the right track. Here is how I would use an event structure to do what you are trying to do.

 

Example.png

Tim
GHSP
0 Kudos
Message 7 of 8
(4,307 Views)

We seem to have a parallel discussion going on. Let's keep it all in one place.

 

 

0 Kudos
Message 8 of 8
(4,304 Views)