From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW Idea Exchange

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

Macro VIs and Code Fragments

Status: New

I'm cleaning up some code that has a lot of stuff like this (much simpler sample code shown):

Loops

The loops are (almost) the same. The normal way to clean this up would be to create a subVI like the following:

Normal

But this has problems. (1) Need to create reference on the calling diagram (2) Reading and setting values by reference (3) Doesn't handle the third loop which has an absolute value. You could deal with #3 by dynamically calling a subVI or having a case structure with an input, but that complicates the design and doesn't make it as flexible (reusable).

 

What if we expanded the idea of inline VIs introduced in 2010. Instead of the compiled code being added to the calling VI, the actual G code is added with input substitutions and then compiled. The 'Macro VI' is replaced by the code inside the VI and the gray placeholder controls/indicators are replaced by the calling VI controls and indicators. This is different from the current inline implementation in that the macro code would be reading the controls/indicators/locals during each iteration instead of just getting the values when the subVI was called. (I believe that is how things are working now, correct me if I'm wrong).

Macro1.png

To handle sections of code that might be different, we could add something like 'code fragments'. Here's an example:

Macro2.png

The orange 'code fragment' gets replaced if wired. The inputs/outputs of the code fragment would have to match.

 

I realize there are issuse if the input controls/indicators have branched wires, etc. Just throwing it out there.

2 Comments
InfiniteNothing
Active Participant

I was also trying to come up with something like this but it got complicated:

http://forums.ni.com/t5/LabVIEW-Idea-Exchange/Custom-Structures/idi-p/1506526

CLED (2016)
Oligarlicky
Member

Regarding code fragments, it's actually a pretty good implementation of anonymous functions. There's currently a way to do this with VI server but your method would be a big shortcut.

anonfunc2.PNG