LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

idea for two variable if statement - help

Hi,

First of all sorry for my English. I have two string variables in combo box or enum such as;

variable 1: "A","B","C","D" and variable 2: "A","B","C","D".

 

i want to write result of combinations of these variables on screen (as string) like;

if variable 1=A and variable 2=A then result=X,

if variable 1=A and variable 2=B then result=Y,

....

if variable 1=B and variable 2=C then result=T,

 

I tried to do it in case structure but i couldn't do it. string output is not possible In formula node. also i dont want to do it with formula node. Thanks for your help and messages.

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

You can do something like concatenate the combo strings and use a case on the result. But it gets more unmanageable the more options you have for the two combos.

0 Kudos
Message 2 of 15
(3,906 Views)

Create an array lookup table and use your enums as the row/column index. 

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

can you upload example 1.vi at LAbview 16.0 version? thank you

0 Kudos
Message 4 of 15
(3,860 Views)

is there a reason not to do it like this?

 

two_enums.png

 

As for formula node not outputting a string you could output the ASCII for the character and type cast to string outside the node. 

 

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

@Aputmans idea is great!

cross reference enums.PNG
/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 6 of 15
(3,836 Views)

the lookup-table and the nested case-structures are totally valid,

but i had some cases where i used something like the following to have less code repitition/more flexibility.

c1.png

which is equivalent to

c1-2.png

 

and for good measure this came also to mind:

c1-3.png


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
Download All
0 Kudos
Message 7 of 15
(3,833 Views)

@jwscs wrote:

the lookup-table and the nested case-structures are totally valid,

but i had some cases where i used something like the following to have less code repitition/more flexibility.

c1.png

which is equivalent to

c1-2.png

 

and for good measure this came also to mind:

c1-3.png


I like the Look-up table approach myself. If working with a-z we have at worse a 26X26 matrix to populate.

 

Editing 600+ cases is not to my liking.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 8 of 15
(3,808 Views)

if it is really only a value that is the output of that, but i thought more in the lines of actions taken, that will be encapsulated by the cases. anyways .. was just for the fun of it 😉


If Tetris has taught me anything, it's errors pile up and accomplishments disappear.
Message 9 of 15
(3,803 Views)

IMHO which method is best to use may also depend on how many distinct cases there are. The OP didn't give much to go on.

 

For a small number of distinct cases, using lists & ranges could be easier to manage. ex.

 

Case 1: "aa", "ab", "ac"
Case 2: "ba", "bf"
Case 3: "ca".."cz"
Case 4: Default

 

For a LUT, you would have to populate ALL the entries in the table regardless, and finding a typo in a 600+ LUT may be like trying to find Waldo.

 

BTW the second example by jwscs could be simplfied. Instead of using a logical shift, integer convertion, and addition it could be done like this

 

using join numbers.png

Message 10 of 15
(3,786 Views)