06-06-2008 09:07 AM
06-06-2008 09:13 AM
06-06-2008 12:16 PM
smercurio_fc wrote:
You should not base the operation of a VI on whether or not an input is wired. It should be based on the value of an input. A subVI should operate in an atomic way. If you want that input to be wired then it should be set to "Required". Otherwise, the VI should not care whether or not the input is wired. It should only care about the value. In the case of a Boolean it's either True or False. That's it. For a numeric you can, set the default value of a numeric to NaN. Then in your code you can check to see if the value of the numeric is NaN, and if so you can use a default value internally. This is sort of testing to see if the input is wired, but the upper level VI could just as well have wired a constant of a value of NaN and the subVI wouldn't know the difference. Again, it's the value that matters.
06-06-2008 12:21 PM - edited 06-06-2008 12:23 PM
Ravens Fan wrote:
If you have two copies of the sameVI which as the default as NaN. If one copy sets the value to something else by a wired connector, then later another copy of the subVI runs with an unwired connector, wouldn't the subVI have the value stored in the control from the first run which was not NaN.
I think that would only be the case with a USR. The default will always take place if there is no value wired, otherwise the USR wouldn't be a special case.
edit - a quick test confirms this

06-06-2008 01:56 PM
06-07-2008 02:34 PM
There is currently no way to know for certain whether or not the input was wired (not even using scripting). It can be done using some black magic (heavy XNode usage), but that is NOT for use in production code. Just make the input required or use an enum instead of a boolean.
There are times when doing it can be very beneficial. For example, consider what happens when you drop a property node - it defaults to the current application instance. The same thing if you change it to the VI class. This is very useful if you want to create "brat" VIs (VIs that control their parents. I believe the term is Norm Kirchner's) or VIs that have a legitimate default behavior. Here's an example. Of course, that won't work with a boolean.
smercurio_fc wrote:
You should not base the operation of a VI on whether or not an input is wired.
06-09-2008 09:02 AM
06-09-2008 09:12 AM
Stepping back and thinking...
If you have a VI that has an optional input that you want to make usre is used correctly, then perhaps you should NOT trust other developers to use it correctly and instead place that VI in two wrapper VI's, one where the optional input has a contant wired to the "optional input" but who's icon connector does NOT have the terminal of interest, and another that does include the terminal of interest and make all of this second wrapper's input required.
By using the warppers you don't have to trust the developers to wire it up correctly.
Use of libraries and public vs private VI's will help enforce proper use.
So, don't worry if the terminal was wired, make sure it is!
Done thinking,
Ben
06-10-2008 02:32 AM
06-11-2008 08:49 AM - edited 06-11-2008 08:50 AM