LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I write a local subroutine in LabVIEW

I have a large software package with a considerable number of subroutines only useable by a single upper level program. I would like to embed these subroutines into the program. I cannot enlarge the program drawing because of coding standards. Is there some way to place the subroutine on the existing diagram, but as a subroutine that is callable anywhere in the program.
0 Kudos
Message 1 of 8
(4,864 Views)
Your question is a bit confusing. Subroutines in LabVIEW are called subVIs and can be placed as many times in the diagram as needed. So if you have subVIs already, I don't see the problem. If you are asking how to take a section of existing code and make it a subVI, select the code, then from the edit menu, select "Create SubVI". There's a lot of information on subVIs in the LabVIEW help.
0 Kudos
Message 2 of 8
(4,864 Views)
I want to take a subVI that is used multiple times in an upper VI, and instead of having it as a separate VI, include it in the diagram of the upper VI. Two pictures on the same canvas if you will. I can do this with two subroutines, but I can't figure how to make one diagram callable by the other
0 Kudos
Message 3 of 8
(4,864 Views)
I think you'll better stick with the subVI. That's a far better design esp.
if you can't (or don't want to) enlarge the diagram.

Cheers,
Carstem
0 Kudos
Message 4 of 8
(4,864 Views)
I still don't understand how you're defining a subroutine but in any case, you can either have all of the code in a main VI or have external subVI's. You could certainly take the code from the subVI and paste it into the main several times but there's no way to reduce that to an icon or single object except when it exists as a subVI. Why are you wanting to do this?
0 Kudos
Message 5 of 8
(4,864 Views)
Any good program uses a modular design. In text-based languages, the source code typically contains multiple subroutines or functions in a single source file. In LabView, the hierarchy is built with sub-VIs, as Dennis and Steve have said. You cannot include multiple VIs in a single diagram. Each VI has its own diagram.
If I understand your question, there is no good way to create "local subroutines" as you see them: one section of the diagram that may get called from multiple places on the same diagram. The dataflow model of LabView doesn't support this. For some applications, it may be possible to build a state-machine that does this in a very limited way, but then you're eliminating some of the benefits of modular code, including the flexibility to use a subrou
tine (subVI) anywhere.
If you simply copy the diagram from the subVI onto the diagram of the calling VI and wire it in, you're creating single-use code (code that gets called only from one place). You'll be sorry if you do this for anything but the simplest application. Modular code is so much easier to develop, debug and maintain.
Click here for some addition discussion on modular code in LabView.
0 Kudos
Message 6 of 8
(4,864 Views)
I am managing (with active changes every day) several hundred VIs. In order to reduce this workload, I am trying to minimize subroutines (sub VIs) to only those used by multiple upper level VIs. I could paste multiple copies into the program, but that would make the diagram unworkably large. Many of our computers have low resolution screens, as they are intended for testing, not test development.
0 Kudos
Message 7 of 8
(4,864 Views)
Reducing the number of VIs can make managing the project harder, not easier. In a more modular design, it is easier to see what changed (and needs review, etc.) and what has not changed.
0 Kudos
Message 8 of 8
(4,864 Views)