LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VI of the Day (9/18/2009) - Code Snippets

Here is one for the early adopters of LV2009, the "Code Snippet".  I have been using LV2009 for less than a week and these things are really starting to grow on me, and given their potential for improving the quality of life on this forum I thought it would be a nice subject to discuss.  It really is pretty simple, just select some code, create a code snippet and you have something like this.

 

MakeNumberArray2.png 

 

A few things I have noticed in my short experimentations.  First, the VI must be saved first.  I think this is a bit of a drag, sometimes I would try to make a quick example to answer a question without really needing to keep the VI.  I have learned to live with it.  Second, no keyboard shortcut by default, this was quickly remedied and is now Shift-Ctrl-C on my computer.  Finally, I was trying to use these to collect bits of code that I reuse frequently, but I missed the ability to label the VI from which they came.  If you look closely at the above snippet, you'll see that I have remedied this as well.  I have attached some code I threw together to add a text label to a snippet file.  Hopefully it is useful in case you don't want to wait for SP1.

 

I have seen a few issues (browsers, references being changed, etc.) being discussed, any other gotchas lurking?  For a first implementation it seems to be quite workable with some room for improvement.

 

For help, check out this site:

http://zone.ni.com/devzone/cda/tut/p/id/9330 

 

VIOTD groundrules here

 

 

Message Edited by Darin.K on 09-18-2009 09:54 AM
Download All
Message 1 of 34
(4,279 Views)

One thing I have noticed (which makes perfect sense and it wouldn't work any other way) and may catch you off-guard is:

  • the Snippet will convert your property nodes to strict and put a reference to it.... also note that my "false" constant got hidden by the big strict node ! Smiley Surprised. You'd have to move the constant over quite a bit to prevent that.

 

snippet vs capture.gif

Message Edited by Broken Arrow on 09-18-2009 10:26 AM
Richard






Message 2 of 34
(4,253 Views)

For some amusement on your Friday afternoon you can check out a less practical code snippet implementation here.

 

http://forums.ni.com/ni/board/message?board.id=BreakPoint&thread.id=8610

Message 3 of 34
(4,211 Views)

Firefox browser doesn't support snippets natively.  You need to get the IE Tab extension.  This runs IE code in your Firefox tab and makes the drag and drop work.

 

Bill

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 4 of 34
(4,190 Views)

Darin.K wrote:

Here is one for the early adopters of LV2009, the "Code Snippet".  I have been using LV2009 for less than a week and these things are really starting to grow on me, and given their potential for improving the quality of life on this forum ...


When theyt demoed this for the LV Champions, I felt the same way. I was hot on using them until I realized most everything invloving a proprty node did not work right and I was confusing noobs by posting non-functional code.

 

But when that issue gets fixed, oh boy!

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 5 of 34
(4,184 Views)

Broken Arrow wrote:

One thing I have noticed (which makes perfect sense and it wouldn't work any other way) and may catch you off-guard is:

  • the Snippet will convert your property nodes to strict and put a reference to it.... also note that my "false" constant got hidden by the big strict node ! Smiley Surprised. You'd have to move the constant over quite a bit to prevent that.

 

snippet vs capture.gif

Message Edited by Broken Arrow on 09-18-2009 10:26 AM

 

 

I have to play straightman here, why does this make perfect sense for a snippet?  Does it actually work?  If there is a fundamental reason why this construct won't play nice with a snippet, I would prefer it if it would give me a plain screenshot and a warning that no code is attached to the snippet.  At least I have a screenshot that shows my intentions.  

0 Kudos
Message 6 of 34
(4,159 Views)

Darin.K wrote:

Broken Arrow wrote:

One thing I have noticed (which makes perfect sense and it wouldn't work any other way) and may catch you off-guard is:

  • the Snippet will convert your property nodes to strict and put a reference to it.... also note that my "false" constant got hidden by the big strict node ! Smiley Surprised. You'd have to move the constant over quite a bit to prevent that.

 

snippet vs capture.gif

Message Edited by Broken Arrow on 09-18-2009 10:26 AM

 

 

I have to play straightman here, why does this make perfect sense for a snippet?


Because the Snippet is a VI. If you select that code on the right and tell LabVIEW to create VI, it would do the same thing (make a strict ref). Maybe it doesn't make "perfect" Smiley Wink sense, but it is logical.

 

Richard






0 Kudos
Message 7 of 34
(4,132 Views)
I wish they treated more like a cut-and-paste operation.  No problems (that I know of) there.
Message 8 of 34
(4,129 Views)

Just to be clear - a snippet is NOT a VI. It is LabVIEW code embedded into a PNG file. Unlike a VI, it does not include a front panel or executable code, just the block diagram. I can't say that I see why this should make the generated code use a reference and I'm assuming it's just an oversight/bug.


___________________
Try to take over the world!
Message 9 of 34
(4,067 Views)

tst wrote:

Just to be clear - a snippet is NOT a VI. It is LabVIEW code embedded into a PNG file. Unlike a VI, it does not include a front panel or executable code, just the block diagram. I can't say that I see why this should make the generated code use a reference and I'm assuming it's just an oversight/bug.


Right. Since it doesn't have front panel code, it makes references. And again, I'm on board with not liking it - just trying to make sense of it.

Message Edited by Broken Arrow on 09-20-2009 01:30 PM
Richard






0 Kudos
Message 10 of 34
(4,053 Views)