LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

vi that can take either strings or numbers

Solved!
Go to solution

I am sure it has been discussed here in the past but I can't find it. I am writing a VI for the manipulation of some array data. I really don't care if it comes to me as a string or as a number array. How does Labview handle this? Basically I want to create an array tool much like the ones in the existing toolbox except I can't see the source code behind those. So how do I create a tool that looks at the incoming data and if it is dbl treats it as so, but if string treates it as string?

 

The first issue is on the front panel VI I have to establish what the linked arrays are. How do I allow for the input of both? Next do I need case structure for dbl vs. string or is there a way to set up a constant that is either or?

 

I hope I am explaining this correctly but I want everything to work like one of Labview's existing array tools. Namely the incoming data comes in in one format and then the paths adjust to handle it automatically.

0 Kudos
Message 1 of 8
(3,015 Views)

Sounds like what you want is a Polymorphic VI.  It's not quite the same as the primitives, but it will do the job.


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 2 of 8
(3,008 Views)

Take a look at creating a polymorphic VI.  You'll have to create one VI for handling a DBL array and one VI for handling a string array, then create the polymorphic 'shell'.  The type of wire you connect to the input will determine which actual VI gets called.

0 Kudos
Message 3 of 8
(3,007 Views)

OR.

This sounds a lot like a call for a "Class" with dynamic dispatch of two override methods.

 

The choice between the LVOOP and Polymorphic approaches depends on the question....

"Will the datatype be known during development or must the vi dynamically chose the vi to run at runtime?" 


"Should be" isn't "Is" -Jay
0 Kudos
Message 4 of 8
(2,990 Views)

It has been a little while since I was working on this but now I am coming back to it. Here's a great example. See my code below for "Is in array".

 

This will be a little subarray, so right now the operator selects the mode and it goes from there. However I know there must be a way to get the data stream to automatically configure based on what it is being sourced. Basically I want my inputs to "Is in array" to change just like the acctual array vi's inside the program do.

 

Any ideas?

Download All
0 Kudos
Message 5 of 8
(2,915 Views)

Without using LVOOP, a variant data type is the only type of wire that can pass more than one type of value.

 

In your code;

 

Try using a type-def'd enum for you cases. It will help you keep the states straight.

 

Experiment with code like this

 

Or_Array.JPG

 

And while I am at it.

 

If you enable indexing on an input array the "N" for the loop is determined by the array size and there is not need to explicitly index array elements.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 6 of 8
(2,905 Views)
Solution
Accepted by adamsdaq

Well, your code could be simplified quite a bit.

 

Again, look into the polymorphic VI.  That and classes are the only real options at this point.


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 7 of 8
(2,903 Views)

Short comment re: The appraoch by crossrulz vs my version.

 

My version is a near one-to-one translation of the orignal code.

 

Crossrulz version is more efficient and will out perfrom my version particularly with large arrays because;

 

Mine cheks all for equality, his stop when it finds a match.

 

Mine creates an intermediary array, his does not.

 

Done with the compare.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 8 of 8
(2,891 Views)