LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Add a stop and error message to code

Solved!
Go to solution

Hi,

I'm slowly starting to understand Labview. I have a working VI. I wanted the VI to not run and display an error message if the user input bad control values.

For exemple, for the number of point, he writes -2, which would make no sense. I would want my VI to not run the rest of the code and have a message display ''Value X is invalid.''

How do I do that in Labview?

Thank you.

0 Kudos
Message 1 of 3
(2,889 Views)

Hi Raphael,

 

how would you do that with any other programming language?

IF value <= 0 THEN
  DialogBox("invalid data input!")
ENDIF

You need a comparison, a case structure and a OneButtonDialog…

 

But: LabVIEW allows you to set input/value ranges for each numeric control! Configure those controls to not even allow the user to input bad values…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 3
(2,885 Views)
Solution
Accepted by topic author RaphaelMT

The best way is to use the error wires. What you need to do is:

  1. Detect the error - You can do this using comparisons (greater than / less than) in your case, but it will depend on your scenario. You can also do it using a case structure, in my example I said that the values 1 through 100 are valid, everything else (default) is not valid.
  2. Trip the error - there are many ways to do this, including a simple cluster bundle, but I like to use the "error cluster from error code" VI, which makes it very easy to see what you are doing. Give it a meaningful message, and stick to the custom error codes range.
  3. Skip any code that doesn't need to be run - You can do this by putting a case structure on the outside of it and making the error wire select the case. This is why a lot of SubVIs have a case structure around them.
  4. Display the error - You can do this with the Simple Error Handler.

Capture.PNG

Capture2.PNG

Message 3 of 3
(2,884 Views)