For simple conditions and actions, the Select Function completes the equivalent job of an if-statement. You can find the select function under Functions» Programming >> Comparison >> Select. The Select Function accepts three inputs. Those inputs listed in order from top to bottom can be seen below:
- The desired output of the TRUE case
- A TRUE/FALSE Selector
- The desired output of the FALSE case
The selector input takes in Boolean data. Depending on the value of the selector data, the Select function returns the value wired to the true or the false input. The true and false outputs can be various data types. See the example below using a string data type.
The select function is useful is you only need to change your output depending on your input. However, if you need to change what code is executed depending on your input, you will want to use a Case Structure.
You can find the Case structure on the Functions Palette under Programming >> Structures >> Case Structure. There are three sections of a case structure:
- The selector label
- The subdiagrams or cases
- Case selector
The Case Structure defaults to one True case and one False case. For each case, you can write LabVIEW code that will be executed if the condition of the case is met.
The Case Structure has a green question mark input terminal called the case selector terminal. For using the case structure in the default True/False cases, wire a Boolean input to this terminal to set the conditions for which case should be executed.
The example below shows similar code to the Select example. The key difference is the with the Case Structure, you able to execute code selectively. (If using a Select function, you would not be able to manipulate your data (i.e. execute code) in a variable way as seen below.)
In this simple example, if the user input is greater than 5, the case selector reads a true Boolean and executes the true case in which the user input is multiplied by a random number. Alternatively, if the user input is less than 5, the case selector reads a false Boolean and executes the false case where the input undergoes a multiplication of larger random number. Each case has distinct code and outputs different from the alternative case.