06-18-2013 07:39 AM - edited 06-18-2013 07:41 AM
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.
06-18-2013 07:44 AM
Short answer to your request:
Use a state machine
Norbert
06-18-2013 11:29 AM - edited 06-18-2013 11:31 AM
@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:
06-19-2013 07:23 AM - edited 06-19-2013 07:24 AM
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.
06-19-2013 07:35 AM
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