LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Get default datatype for input on a vim?

Solved!
Go to solution

I'm making a vim to do some array manipulation, and I need to pad it with default values. I feel like I'm overlooking something obvious... but how do you get a default value of an arbitrary wire's datatype?

 

This isn't my actual application, but say I want a .vim that will create an array with n elements of some datatype, but I want them to be the default value of the datatype. This is what I'm currently using:

 

Default value for array.png

 

A For loop with 0 iterations will just pass the type, not the actual value, so I end up with this, which works:

 

new array of type.png

 

So this works, but the zero iteration FOR loop feels Rube-Goldberg-esque to me and it's not super apparent at first glance what's going on for someone trying to read my code. Is there a better option?

0 Kudos
Message 1 of 13
(2,504 Views)

I don't have a great answer, but I don't think that many people are around today, so I'll take a shot 🙂

 

I played around with it for a few minutes and you can use the "Type Specialization Structure" to accomplish it where you have one frame for each data type expected.

 

That having been said, I actually don't see any problem with what you posted.  The Type Spec structure is more verbose, but adding a simple comment to the for loop along the lines of "0 iteration to pass data type not value" would be enough for me to understand what was going on in the code.

 

 

0 Kudos
Message 2 of 13
(2,468 Views)
Solution
Accepted by topic author BertMcMahan

Personally, I find the Diagram Disable Structure to be slightly cleaner than the 0-iteration For Loop.

 

DDS_TypePropagation.png

Message 3 of 13
(2,388 Views)

Looks all fine to me. A zero iteration FOR loop is a perfectly legal (and sometimes useful) tool. 😄

 

You could also do something like that.... (Probably very similar code under the hood ;))

 

altenbach_0-1577843809393.png


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 4 of 13
(2,384 Views)

Why not use the output of a disabled structure? Wire the data type through the disabled case. Leave the enabled case unwired. The data type will be there, the value will be default.

As mentioned.. *SIGH*

0 Kudos
Message 5 of 13
(2,173 Views)

Do the zero-iteration-loop and diagram-disable methods behave the same for child-class objects on parent-class wires?  Do they return default child or default parent objects?

0 Kudos
Message 6 of 13
(2,154 Views)

@drjdpowell wrote:

Do the zero-iteration-loop and diagram-disable methods behave the same for child-class objects on parent-class wires?  Do they return default child or default parent objects?


Just tested this to make sure. Both behave exactly the same: You get the default of the exact class that's wired. Wire a child, get a default child. Wire the parent, get a default parent.

0 Kudos
Message 7 of 13
(2,136 Views)

@Darin.K wrote:

Personally, I find the Diagram Disable Structure to be slightly cleaner than the 0-iteration For Loop. 


I know Stephen Loftus-Mercer recommends the Diagram Disable Structure method.  And it is also used in built-in functions such as the Remove Duplicates From 1D Array.vim.


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
0 Kudos
Message 8 of 13
(2,118 Views)

Thanks for the replies everyone. I like the DDS better than the FOR loop so I will go with that from now on.

 

I'd actually looked in a couple of the array manipulation vim's and didn't see a DDS but I must have just missed it.

0 Kudos
Message 9 of 13
(2,089 Views)

wiebe@CARYA wrote:

@drjdpowell wrote:

Do the zero-iteration-loop and diagram-disable methods behave the same for child-class objects on parent-class wires?  Do they return default child or default parent objects?


Just tested this to make sure. Both behave exactly the same: You get the default of the exact class that's wired. Wire a child, get a default child. Wire the parent, get a default parent.


I found the opposite, though I might have explained my query badly.  Here is an image.  I use a parent-class wire, but feed in a child object at run-time.   The zero-iteration loop returns a default child-class object, but the Diagram-Disable structure returns a default parent-class object.   These two techniques of getting a "default" value are thus not identical for Objects, and one should choose which behaviour one actually wants.

Zero-iteration loop versus DDS.png

Message 10 of 13
(1,933 Views)