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: 

Button that execute block code.

Solved!
Go to solution

Hello.

 

I want to execute a block of code with the push of a button but I cannot find the solution.

Attached is my vi. Any help is welcomed.

 

Thank you.

0 Kudos
Message 1 of 11
(3,486 Views)

Hi vakost,

 

some pseudocode:

IF button is pressed THEN
   call subVI
ENDIF

 In LabVIEW the Case structure resemble the IF-THEN-ELSE. Don't you think you can get it starting from here?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 11
(3,478 Views)

Hello and thank you for the quick reply.

 

I do not understand what you mean.

I do have both cases of the case structure covered, yet, it is not working.

 

Thanks again.

Vasilis.

0 Kudos
Message 3 of 11
(3,474 Views)

Hi Vasilis,

 

attach your Vi in LV2011 so I can have a look at it…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 11
(3,470 Views)

Hello again!

 

It is attached in my first post, but I am attaching it again in case there is a problem.

 

Thanks.

Vasilis.

0 Kudos
Message 5 of 11
(3,465 Views)

Hi Vasilis,

 

there's a reason why I asked for the LV2011 version…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 11
(3,458 Views)
Solution
Accepted by topic author vakost

Hello vakost;

 

A few points:

 

- The mechanical action of your Boolean is set to "Latch when Released". This means it will reset to False after being read once.

- You have no software control timing in your loop, this is what's known as a "greedy loop" and will execute as fast as it possibly can

 

Due to this, your True case will execute, but only once when you release the button, and the button will be reset to False before you likely see it because the loop is probably running many thousands of times per second. If you turn on execution highlighting to slow down the VI's execution to something you can observe, you should see the Boolean indicator turn on briefly before resetting.  You should still place a wait function inside your loop to slow things down to a reasonable speed, however.

 

A few other tips:

 

- You don't need to place the Boolean indicator inside the case structure if you want to update it in either case (you're using a value property node in the other case) - just place it outside the structure and wire the value you want to set out of the case

- You've created a while loop with no stop condition, and the VI has to be aborted to stop it.  Generally you'll want to give the user a stop button to exit the VI, aborting is almost never a good idea.

Regards,

- You don't really need the case structure in this circumstance, you could just wire the Boolean OK button directly to the indicator.  My impression is that this is just a demonstrative example or experiment in how case structures work, though, so that's probably alright.

 

Hope that helps!

Tom L.
0 Kudos
Message 7 of 11
(3,451 Views)

!!

 

I am so sorry! I didn't even notice! I don't have an earliest edition but I am attaching the pictures.

 

Thanks.

0 Kudos
Message 8 of 11
(3,447 Views)

Do you have a while loop around the case structure so that execution continues to run, checking the boolean for a new value?

 

EDIT:  picture attached now. 

 

I can't open VI either.

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 9 of 11
(3,444 Views)

Your VI is in LabVIEW 2013, in case you don't know.

 

I would recommend to start here. There are way too many things wrong with your code, mostly misconceptions.

 

(Why do you think you need a value property node? Simply connect the LED to the switch. Why do you think you need to poll that switch as fast as the computer allows, millions of times per second, consuming all CPU? How do you stop the VI? You don't see anything because your button is latch action, meaning the LED only goes on for a nanosecond when you press it. Change the machanical action!, slow down the loop with a small wait statement, etc.!)

0 Kudos
Message 10 of 11
(3,438 Views)