LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to create a subvi

hi there. i have a question with subvi that i can't seems to figure out.
i read over the "SubVi" chapters in the book but it doesnt say about this issue i want to addresss.

There are 2 major reasons you should use subVis
1) performing the same tasks at more than one place in your program
2) block diagram becomes too big

I have both of that reasons in my main vi (parent vi).

If i just create new vi
copy and paste the things i see that are used very often into a subvi
do i have to connect it out using terminal pattern or something?

to clear things,
i have Pressure and Pressue2
If my main Vi called my subVi and the value of Pressure and Pressure2 is changed in the subvi, after the subvi finished its task, will it update Pressure/Pressure2 or i have to connect them to a local variable of the main vi in order for it to update?
thank you for your time.

i have attached the block diamgram that i see quite often throughout the main vi and i think this portion can be put into a subvi, but i dont want to do it wrong and break the main vi in any ways.
can someone please help me.
thank you

Best regards,
Krispiekream
0 Kudos
Message 1 of 41
(7,692 Views)
Hi krispiekr...,
i don´t really understand your attached vi. If you create a sub vi and you want to use it you need inputs and outputs. There is no need to use local varibles. If you change a value in your sub vi, create an indicator and connect the new result to it. If you do it, you can use the result in the main vi, from which you have called the sub vi.

Hope it helps.
Mike
Message 2 of 41
(7,685 Views)
Hi krispiekr...,
i don´t really understand your attached vi. If you create a sub vi and you want to use it you need inputs and outputs. There is no need to use local varibles. If you change a value in your sub vi, create an indicator and connect the new result to it. If you do it, you can use the result in the main vi, from which you have called the sub vi.

Hope it helps.
Mike


I see what you mean, so i need to have inputs from my main vi into my sub vi.
and then my subvi have to have an output so that it goes back into my main vi.
so that vi i have attached its not really necessary to create that as a subvi then?
the attached vi is the block diagrm portion that i see very often throughout the main vi.
it is doing the same tasks so i want to create a sub vi. how would i go about making a subvi so that part of the code?

it will take me the same about of block diagram space and local varibles to create inputs and outputs of the subvi.
how would i create input and output without using local variables of the main vi? use wires right? but doing that could also means that my wires would be all over the place.



Message Edited by krispiekream on 07-09-2008 01:38 PM
Best regards,
Krispiekream
0 Kudos
Message 3 of 41
(7,679 Views)


@krispiekream wrote:
how would i create input and output without using local variables of the main vi? use wires right? but doing that could also means that my wires would be all over the place.


Hi krispiekream,
local variables don´t help you in a subvi, because you can use them only in the subvi. You can create controls/indocator on the front panel or you create a constant in the block diagram and right click on it to select "change to control" or "change to indicator". Switch to the front panel and right click on the icon, select show connector pane. There you can assign each input/output with a control.
It could be that you have more wires without using local variables, but you should never use locals to minimize the wires.

Mike
Message 4 of 41
(7,674 Views)
One way to create a subVI with all the connector pane connections already made is to go to the block diagram of the main VI (or any from which you wish to create a subVI). On the block diagram select the section of code which you want to convert to a subVI. Then from the Edit menu choose: Create SubVI. This will create a subVI with suitable controls and indicators for all the wires going in and out. You can then open the subVI and make any editorial changes necessary, like putting descriptive names on controls and arranging things nicely on the panel and diagram. Add documentation to the VI properties, edit the icon, and save the subVI.

Note that the selection on the main VI diagram should not contain any terminals of controls or indicators or any of your local variables as this will generate warning messages and may cause it to not work as you expect.

This is very useful for the kind of clean up you are trying to do.

When you do this, try to group together code which logically belongs together, not just pieces which happened to be close by on the diagram. A subVI with random "chunks" of code will be hard to understand six months from know when you need to modify something.

If the subVI contains code which is duplicated on your main VI, just drop another copy of the new subVI near the duplicated code, connect it up, and delete the original code.

Lynn
Message 5 of 41
(7,668 Views)
this is what i did. according to lynn suggestion.





i feel that doing still slows down the process of the program. is that true?





Message Edited by krispiekream on 07-09-2008 03:19 PM
Best regards,
Krispiekream
Download All
0 Kudos
Message 6 of 41
(7,643 Views)
You should wire the error cluster directly and not use a reference.
 
As for the rest of the code, you'd have to post it because we only see frame 1 in the stacked structure.
 
By the way, were you not getting rid of stacked structures? 😉
 
R
Message 7 of 41
(7,618 Views)


You should wire the error cluster directly and not use a reference.
 
As for the rest of the code, you'd have to post it because we only see frame 1 in the stacked structure.
 
By the way, were you not getting rid of stacked structures?
 
R


yeah. i posted the code in the first message and i dont know how to get rid of the stacked sequence since its called to
first frame TRUE GLOBAL
second frame TASKS
third frame FALSE GLOBAL.

can you look at the code and see what advice you can give me.
thanks

Best regards,
Krispiekream
0 Kudos
Message 8 of 41
(7,616 Views)

Is it the very same as the one you posted earlier called help with subvi?

R

Message 9 of 41
(7,614 Views)
yes
i am thinking that if i cant get rid of the stack sequence. i might was well not show the messy programming by making a subvi for it.
hahaha. Smiley Indifferent


Message Edited by krispiekream on 07-09-2008 07:05 PM
Best regards,
Krispiekream
0 Kudos
Message 10 of 41
(7,611 Views)