LabVIEW Development Best Practices Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

conditional control input to a subvi

Solved!
Go to solution

lets say a subvi takes in as input whether the input is a vi path or a vi reference and the path/reference.

what is the best control for the input that decides whether a path/reference is being provided ?

i've considered using a boolean (say true for path and false for reference) but it does not seem intuitive (is there any way of making it seem intuitive?)

enum can be used too but that seems a bit too much for a simple 2 way conditional thingy;

string constant input requires string matching which is again overdo

(i've attached a vi for reference & to add clarity)

0 Kudos
Message 1 of 5
(4,984 Views)
Solution
Accepted by shrewquest

There are a few ways to handle this.

  1. Check to see if you have a proper reference.  If not, open the VI using the path.
  2. Use a polymorphic VI.  One instance for the reference and another for the path.  The instance that uses the path and then call into the one that uses the reference to make coding even easier on yourself.

The polymorphic would probably be the best way to do this.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 5
(3,807 Views)

Hi

In these cases, I have several times been able to determine internally whether to use the path or path reference.  -This works if you can say "if both are valid, I always want to use x" or if you can say "only one of these will ever be passed a valid value".  In these cases, you can use "is path/refnum" type primitives inside the VI to determine which input is valid, and if both are valid, to pick one.  Make sure to use "not a path" and empty ref controls as default values in your VI.

I realize this is not quite what you are asking and that you might already have considered this option?

I modified your example to show one way to do this... err.. but I can't add files?  So I stitched together some screenshots.

(Note I left two indicators on there just to show the logic better.)

block diagram.png

QFang
-------------
CLD LabVIEW 7.1 to 2016
Message 3 of 5
(3,807 Views)

bah crossrulz beat me to the punch while I was screen shotting.

QFang
-------------
CLD LabVIEW 7.1 to 2016
0 Kudos
Message 4 of 5
(3,807 Views)

It seems like a better API choice in this case might be to use 2 VIs, either seperate or a polymorphic VI. If you look at the Write File VIs in LabVIEW they use a polymorphic solution to this (admittedly natively)

James Mc
========
CLA and cRIO Fanatic
My writings on LabVIEW Development are at devs.wiresmithtech.com
0 Kudos
Message 5 of 5
(3,807 Views)