cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

idea for two variable if statement - help

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
(495 Views)

Re: idea for two variable if statement - help

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
(489 Views)
Highlighted

Re: idea for two variable if statement - help

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

aputman
LabVIEW 2017
LabVIEW Programming
Message 3 of 15
(470 Views)

Re: idea for two variable if statement - help

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

0 Kudos
Message 4 of 15
(443 Views)

Re: idea for two variable if statement - help

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
(425 Views)

Re: idea for two variable if statement - help

@Aputmans idea is great!

cross reference enums.PNG
/Y

G# - Award winning reference based OOP for LV, for free! ADDQ VIPM Now on GitHub
"Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
Certified-LabVIEW-Developer
Message 6 of 15
(419 Views)

Re: idea for two variable if statement - help

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.
0 Kudos
Message 7 of 15
(416 Views)

Re: idea for two variable if statement - help


@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

0 Kudos
Message 8 of 15
(391 Views)

Re: idea for two variable if statement - help

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 Smiley Wink


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

Re: idea for two variable if statement - help

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
(369 Views)