LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there something to avoid repeating code ?

Another question for today 🙂

 

Imagine I have a code like the one pictured below. The code acheives nothing, it is solely to provide a simple example.

There is a part of code which is repeated twice (3 strings are set to void).

What I would like to do is to "hide" this code into a sort of subVi. I do not really want a subVi, because a subVi, will create 3 inputs which are the reference to the 3 string controls.

So what I want is not a subVi, is just a way to hide a portion of code which is trivial and I don't want it to occupy space on the block diagram.

Imagine I have 50 string controls to reset in 5 or 6 places in my code, It would be nice to have such a feature. A subVi will just want 50 inputs (one for each string)

 

Of course you would say that doing this is confusing, you cannot reuse it, ect ect.

Is there any way to do it ?

The "hidden code" will appear just an ordinary subVi, without any inputs ot outputs.

Clicking the small box, will show you the code just like a subVi does.

 

 

 

A.png





0 Kudos
Message 1 of 5
(2,288 Views)

Short answer to your request:

Use a state machine

 

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 2 of 5
(2,281 Views)

@Runawaycode wrote:

[... ] Imagine I have 50 string controls to reset in 5 or 6 places in my code, It would be nice to have such a feature. A subVi will just want 50 inputs (one for each string)


 

A subVI can also take just a reference to the Front Panel.  Just iterate over all of the String controls like this:

 

Example_VI_BD.png

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 3 of 5
(2,238 Views)

Ok guys, thank you for the answers.

I understand there are properties, state machines, loop, etc....

 

What I would like to do is something similar to what I can do wih a text based programming language, e.g.

look at the code below. If I click the minus sign that I circled, I just hide text in brackets.

Hide and nothing else.

What I would like is something similar in the LabView G code.

I understand that this is trivial to acheive in a text styled code, where you just have to graphically remove n lines.

In a 2 dimensional graphic styile code this is not so simple to define, but take the simplest case where I haven't any wires going in and out my selection I see no troubles doing it.

 

 

a.JPG

 

 





0 Kudos
Message 4 of 5
(2,195 Views)

Yes and no.

To answer your question in the title: Experience! Sub-vi's, state machine and other solutions are tools to solve the problem of not repeating code.

To answer your question in the text: State machines and sub-vi's are a way of "hiding" code, but more so a way of structuring it and allowing reuse. Code hiding in general is frowned upon in the LV community which is one reason stacked sequences is very much frowned upon. As for a funcionality to dynamically hide code, then no, unless you count sub-vi's.

In your example i'd make an ActionEngine which i'd fill with an array of references at program start (to the various string controls) with the action Init (which stores references) and Clear (which empties stored string references).

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 5 of 5
(2,191 Views)