LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

wires are better than local variables?

Solved!
Go to solution

You have three inputs X,Y and Z right?

 

  1. Perform the two logical comparisons and build the two boolean outputs into an array, and search the array for a TRUE.
  2. Use the numeric output from the 1D array search function to drive the selector node of a case structure.
  3. Give the case structure three cases: 0, 1 and Default.
  4. Put the calculations to derive the Num output in their respective cases and the calculation where neither comparison is true inside the default case.
  5. Place the num indicator terminal outside the case structure and wire the values calculated inside the case out to the terminal.

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...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 11 of 20
(1,053 Views)

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

0 Kudos
Message 12 of 20
(1,035 Views)

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...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 13 of 20
(1,026 Views)

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 

0 Kudos
Message 14 of 20
(1,019 Views)

Here are a few different ways you can select cases for a case structure.

 

Case Selection Methods.png

 

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.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 15 of 20
(1,004 Views)

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:

caseselector.png

 

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!

0 Kudos
Message 16 of 20
(996 Views)

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...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 17 of 20
(987 Views)

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

0 Kudos
Message 18 of 20
(970 Views)

Thanks for your idea Mark. I can use it somewhere else 🙂

 

Regards

sarkar

0 Kudos
Message 19 of 20
(969 Views)

@Mark_Yedinak wrote:

Here are a few different ways you can select cases for a case structure.

 

Case Selection Methods.png

 

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

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 20 of 20
(950 Views)