03-19-2012 08:43 AM
You have three inputs X,Y and Z right?
If you don't understand these instructions work through a few of the tutorials that ship with LV and try again - or post more questions here.
Mike...
03-19-2012 11:56 AM
Thanks Mike for your patient explaination. I have solved my problem and using case seems like a better idea. The if structure i posted didnt exactly represent my logic. Heres what i have done in LV and works great.
Regards
sarkar
03-19-2012 01:01 PM
That looks fine. The goal of what I posted was to implement the logic up front and combine everything into a single case structure, but yours will work fine too.
Mike...
03-19-2012 01:32 PM
Well building an array sounds like a good idea but the selectors are of different datatypes. So had to use nested case structure. Thanks for replying 🙂
Regards
sarkar
03-19-2012 03:17 PM - edited 03-19-2012 03:18 PM
Here are a few different ways you can select cases for a case structure.
The combinational logic is basically what ike was suggesting. Nested loops can work but can become extremely hard to follow once the nesting gets too deep. You also end up repeating lots of the same checks.
03-19-2012 03:41 PM
Once you start nesting case statements, it becomes harder to keep track of the possible results. An alternative would be to use the Select node, for example, I've rewritten your case statements with Select nodes:
Writing it this way allows you to see all of the logic together. But certainly no need for local variables here, or in most situations!
03-19-2012 04:39 PM - edited 03-19-2012 04:40 PM
Exactly! Another excellent point that you raise is that the best of all possible worlds is if you can refactor your logic such that the case structure goes away completely. Even a non-nested case structure can hide a lot of code and can be dificult to refactor in the future.
An added bonus is that depending upon how you approached the logical design in the first place, the selectors may actually give the added benefit of more closely matching the thought process you went through in designing the logic. Any time you can give the person maintaining your code a hint as to what you were thinking when you did something, it's A Good Thing - which is why I really like the Compound Arithmetic node. But that's a rant for another thread.
Mike...
03-19-2012 11:31 PM
Actually i did implemented the ditto combinational logic before using the case structure. I think execution of case structure would be faster and its better to keep it like that. Yes it may be difficult to track the cases but labelling helps!
Thanks for your reply Greg
Cheers
03-19-2012 11:34 PM
Thanks for your idea Mark. I can use it somewhere else 🙂
Regards
sarkar
03-20-2012 07:39 AM
@Mark_Yedinak wrote:
Here are a few different ways you can select cases for a case structure.
The combinational logic is basically what ike was suggesting....
and for bonus point from the readers of your code call apon TypeCast Man
![]()
...as I illustrated in this thread where casting the numeric as an enum can make deciphering your code much easier.
have fun,
Ben