BreakPoint

cancel
Showing results for 
Search instead for 
Did you mean: 

Rube Goldberg Code

Re: Delete sub-vi

Maybe he's being paid by the "complexity" of his code.  If he generated a load of unneccessary code, maybe his pointy-haired boss would be impressed and give him a raise.....

Cynical, me, nah.

Shane.

PS Check our dilbert today (25.Jan 2007)

Message Edited by shoneill on 01-25-2007 04:52 PM

Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
Message 31 of 2,571
(28,654 Views)
OK, here's another typical case that shows up once in a while. In this example, we need to turn on one (exactly one) of 100 LEDs depending on some number.
 
We could just initialize a 2D array of FALSE booleans once outside the loop and replace a single element with TRUE using code the size of a postage stamp. Then display the 2D array directly, possibly with a label overlay. 🙂
 
 
...or we could spend days, if not weeks, creating a case structure with 100 cases, each containing "a boolean and 99 local variables" (Isn't there a song about this 🐵 .
(For a small number of individual booleans, the code suggestion shown on the right would be reasonable too.)
 

 
Adapted from:

Message Edited by altenbach on 01-25-2007 08:02 AM

Message 32 of 2,571
(28,655 Views)

JoeLabView a écrit:

Here's one such sub-vi within that code.  Not that it's wrong... Just : WHY???  (PS: that is the entire content of the sub-vi)

 

Message Edited by JoeLabView on 01-25-2007 10:37 AM



Well... What about that one that comes with OpenG VIs ??




Message Edité par TiTou le 01-25-2007 05:14 PM


We have two ears and one mouth so that we can listen twice as much as we speak.

Epictetus

Antoine Chalons

Message 33 of 2,571
(28,648 Views)


JoeLabView wrote:
Here's one such sub-vi within that code.  Not that it's wrong... Just : WHY???  (PS: that is the entire content of the sub-vi)


Hmmm... maybe the custom subVI has a much nicer and more descriptive and intuitive icon. 😮 Maybe it has the old style icon (from a few versions back) for nostalgic reason or to avoid being completely confused by all these new style file tools.....?

Of course it could have real hidden functionality, e.g. a FP with lots of explanatory text next to the file name display that prints on completion so you have a hardcopy of what got deleted. 😉

Message Edited by altenbach on 01-25-2007 08:17 AM

Message 34 of 2,571
(28,648 Views)

nope.. all it does is delete a file..

Back to youe example to turn on one (exactly one) of 100 LEDs depending on some number.  Picture that example.  Replace the Case Structure with a Stacked Sequential Structure.  100 wires to the left. 100 wires to the right.  And the vi is to initialize an array.

I've been reviewing some of my code.  I saw a R-G code of my own...  I'll post it with an explanation of how it came to be,..  and how easy it is to fall into this trap!!!

As Ray F mentionned earlier, we're all guilty of this at some point or other!

🙂

0 Kudos
Message 35 of 2,571
(28,627 Views)

Here is one I caught this morning of my own doing...

How did this happen?  Simple...  It started out that the Case Statement contained a a full (sub) vi. 

From the beginning...  A Case Statement was created to select one of two Spectrum Analyzers to do a "quick" measurement.  Since equipment is shared, one of the two may appear as part of the setup.  Later, programmed evolved and the Case Statement moved elsewhere (and duplicated).  At some point, the instrument initialization routine was taken out of the sub-vi's within this particular Case Statement. 

Lo & Behold..  After another mod, the sub-vi then became a simple VISA Write function (that was part of the evolution.  And ther was No need to have a vi for that.).  Then the same was done (at a later date) for the other SA. Most likely noticed after a switch, where the VI was no longer "suitable".  So then, both cases became a simple VISA Write... Which is what you see in the picture..  Of course the code was done in a hurry, with little thinking and even less coffee!!!  😮

I can already hear the laughter! 😄

 

Message Edited by JoeLabView on 01-25-2007 12:50 PM

Message Edited by JoeLabView on 01-25-2007 12:54 PM

Message 36 of 2,571
(28,626 Views)
The challenge is to cast a two-byte string into an integer.
 
Let's see, that's easy!
  1. Convert the string to a byte array with two elements
  2. split the array at position 1 creating two U8 arrays with one element each.
  3. Join the two arrays, creating an U16 array with one element
  4. Use "delete from array" (!!!), ignore the "array with subset deleted" output, and tap into the "deleted portion" to get the first element in the array.
  5. Tap head and rub belly at the same time
  6. ...
 

Message Edited by altenbach on 02-24-2007 01:07 PM

Message 37 of 2,571
(28,497 Views)
And here's another one:

into:

Ton
PS:
and even the tab and %.3f constant are optional...

Message Edited by TonP on 02-25-2007 12:21 AM

Message Edited by TonP on 02-25-2007 12:22 AM

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
Download All
0 Kudos
Message 38 of 2,571
(28,492 Views)
I'm happy that the array wasn't much bigger (or we would  have probably needed to order another spool of LabVIEW wire from NI). 😮
 
The code is actually not that bad. I've seen similar but with many individual, explicitely wired "index array" nodes on the left. One for each element.
 
(btw: the format string is a required input for spreadsheet string to array, at least in all versions I ever used. However, the enforcement is quite lax: You can wire an empty string as format and the broken run arrow disappears immediately. Run it and the result looks just fine. :))

Message Edited by altenbach on 02-24-2007 03:47 PM

0 Kudos
Message 39 of 2,571
(28,492 Views)
I should post Front Panel RG-code...  One I had to edit was over 3 - 21" monitors high..  😮
Message 40 of 2,571
(28,398 Views)