01-09-2012 09:26 AM
Hi everyone. I have been looking for a way to implement an "if" statement for a while now on my programs with no success, so I was just wondering how people do this in LabVIEW. For example, I have 2 different streams of data coming in (hex format) and would like to do seprate things with it. Normally, I would write a program to say:
x = aa;
y=bb;
if (data == x)
then perform computations on this x data
else
if(data == y)
then perform computations on this y data
However, the case structure seems to only work on boolean values. How would one go about writing this code? Can I implement some sort of comparison vi which triggers a true/fase switch? Thanks very much.
01-09-2012 09:31 AM - edited 01-09-2012 09:33 AM
You can wire a string to a case structure. You can also wire integers. You need a default case or you will get an error. You do not need a default for a boolean as long as you have two cases and you do not need a default for an enum (integer) if you have a case for each item in the enumeration.
01-09-2012 09:35 AM
If your data is a "short" string you can connect it directly to the selection terminal of the case structure and then create case for each value you want to be able to catch PLUS a default case for all other value.
If it's the same with decimal numbers.
If you data type is different then you have implement a more complexe condition detection.
Tell us more about your data type so we can tell you what the best option is.
Hope this helps
We have two ears and one mouth so that we can listen twice as much as we speak.
Epictetus
01-09-2012 09:38 AM
You stated "I have 2 different streams of data coming in "
Since LabVIEW is a dataflow language you do not need to determine wheather the data is sourced from X or Y but simply wire the x data to the x process and the y data to the y process.
Case structures work with most base data types booleans, strings, integers and the error cluster (which it treats specially as a boolean) . Look at the state machine design pattern for examples (File>>New...\Vi \Framworks\Design Patterns\ Standard State Machine)
01-09-2012 09:50 AM
Got it, thanks everyone. I am writing it now, if I have any questions I will be sure to post my program. Thank you.