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: 

Creating a button

Hello,

My goal is to create a button that will display the sum of two random integers in a frequency chart one at a time. Every time this button is pressed, a new value should be displayed. I also need to create a button to clear the data in the frequency chart.

 

So far, I am able to run the program and put my values on the chart. However, I do not know how to create a button to display them one by one, or create a button to clear the data.

 

Thanks for the help.

0 Kudos
Message 1 of 6
(3,086 Views)

Are you sure you attached the right program? There is only one button. There is no chart. (I don't even know what a "frequency chart" is.). I doubt your problem is with "creating" a button. Buttons are right there in the palette. Seem you have problems with programming.

 

There is only a stop button and while the program is running, it generates millions of values per second, spinning the loop as fast as the computer allows and storing all data in a auto-indexing output tunnel. Once the stop button is pressed, the gigantic array is displayed in an array indicator (unless your ran out of memory first). In any case, this seems to have little to do with your questions.

 

I recommend doing a few basic tutorials.

0 Kudos
Message 2 of 6
(3,066 Views)

Learn to use an Event Structure.  With it, you wait for specific things to happen such as button presses.


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 3 of 6
(3,040 Views)

It sounds like what you want is a histogram, and as crossrulz said, you need an Event Structure. 

 

This can register for button press events, and used inside a While loop will allow you to run specific code when different buttons are pressed. 

 

So long as the timeout isn't set to 0, it also acts to limit the rate of your while loop. 


GCentral
0 Kudos
Message 4 of 6
(3,026 Views)

Be sure o follow all other advise... If you really want to put a text in a button, use the Boolean text property. Make sure it's set to visible with right click>visible items.

0 Kudos
Message 5 of 6
(3,013 Views)

Here are a few simple rules you might have missed in class.

 

  1. A terminal that is wired after the loop will not receive any data until the loop has finished. All indicators that should update with every user interaction belong inside the loop.
  2. There is no need for duplicate code. (if you use an inner FOR loop with two iteration, you only need one "dice", one "round", one "6" and one "multiply.)
  3. If a "frequency chart" is (in your world) actually a histogram plot counting the occurrences of each possible result (2..12), just initialize an integer array with 13 elements before the loop and keep it in a shift register. With each new sum, Increment one of the elements using the sum as index. (the IPE Structure works well for that). There are plenty of examples if you search the forum here.
  4. As suggested, you can event structure with a case for each action. (throw dices, clear histogram, stop)
  5. Place the histogram on the array wire before the event structure so it correctly updates when the program is started, but not button has been pressed yet. No timeout event needed.
0 Kudos
Message 6 of 6
(3,008 Views)