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: 

Better way to implement a help button?

Solved!
Go to solution

I wanted to put a "help" button in my program in case the user needs to know what to do. My first try was to add an event structure, but that seemed to make the program hang up which I do not really want. The flat sequence is because I don't know how else to make it wait for the user to create a new spreadsheet file. I feel like there must be a nicer way to do this than with three while loops and local variables, but I don't quite know how... Thanks for any help, photo is attached.

help_button.JPG

0 Kudos
Message 1 of 15
(3,167 Views)

For the help display, use an event structure.  Add an event case for the Help button Value Change.  When the user clicks the button, the event fires and whatever code is in the event case will execute.  Put the event structure in a while loop and set the timeout (hourglass) to 100mS.  That way the user can press the help button over and over, and if the user never presses the button, the timeout will make sure that the event structure executes at least once so that your code won't hang there.  You will also need a stop button to stop the event loop.

 

As for local variables, it is best to use wires.  Where is the code that produces the values?

- tbob

Inventor of the WORM Global
0 Kudos
Message 2 of 15
(3,143 Views)

After thinking about your code, I would suggest you use a state machine.  I have included a simple state machine example that would suit your purpose (in LV2010).  Modify as needed.  Be sure to have the error wires just as they are.  They control the execution flow.

 

- tbob

Inventor of the WORM Global
Message 3 of 15
(3,130 Views)
Solution
Accepted by topic author Gregory

You already got some good advice, so let's quickly look at your original code for problem areas:

 

 

  • SInce you use a popup that blocks the local while loop while it is visible, it needs to be in a seperate loop. So that's good. Still, instead of constantly spinning that loop, an event structure is better. Since you can also sense the stop event, you can eliminate the local variable and set the stop button back to latch action as it should be. 😉
  • One thing you probably forgot is to uncheck "lock front panel until event completes", so the front panel on the calling VI remains unresponsive until the popup is closed again. Personally, I would make the help a simple dialog subVI and use an event to toggle the visibility of the front panel of the help window instead. Since this is not blocking, it can potentially be done in the main loop.
  • To stream data for long periods of time to a file, you should use low-level file IO. You are creating a lot of overhead opening and closing the file with each iteration. Open a file reference, Write the header before the loop, keep appending inside the loop, and close the file one the loop has finished.
  • Depending how long the sample intervals are, you should do the writing to file in the timeout case of an event structure and add a stop case. This makes it easier to immediately stop the VI, even if the wait is set to minutes or hours. If other events are allowed, you need to ensure that the timeout is adjusted accordingly to retain equal pacing. (See e.g. this old example posted here)
  • Get rid of the sequence structure and that idiotic loop on the left. Keep the timeout in a shift register initialized with -1 (=infinite) and add a start event where you set the timeout to the desired value.
  • Soon you have a nice state machine... 😄

 

Message 4 of 15
(3,111 Views)

Well, I've been working on it, but I want the "Help" button to be available even before you start, so I was trying to do it all inside an event structure. I am not sure how to open a reference to the spreadsheet exactly

0 Kudos
Message 5 of 15
(3,102 Views)

Here is what I've worked out so far... with the data given by a random number generator in case you want to run it. The part I am still hung up by is that it seems like the "help" button still pauses everything. Also, I am not sure how to make the spreadsheet writing take up less resources. Thanks for the input!

0 Kudos
Message 6 of 15
(3,091 Views)

Never mind, I believe I have just about done it! There is one extra file close/open than necessary, but not with every single write operation. Thanks for all the help!

Download All
0 Kudos
Message 7 of 15
(3,067 Views)

You don't need to convert to a 2D array, just wire the 1D array to "array to spreadsheet string".

0 Kudos
Message 8 of 15
(3,057 Views)

Alrighty, thank you much!

0 Kudos
Message 9 of 15
(3,005 Views)

  • Depending how long the sample intervals are, you should do the writing to file in the timeout case of an event structure and add a stop case. This makes it easier to immediately stop the VI, even if the wait is set to minutes or hours. If other events are allowed, you need to ensure that the timeout is adjusted accordingly to retain equal pacing. (See e.g. this old example posted here)

  • Just out of curiosity, how come they use a wire running to the case structure, although they don't use the value from it?

    0 Kudos
    Message 10 of 15
    (2,908 Views)