LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to write a sub VI to accept two enums and decide if both of their strings are equal?

Hello,
 
I would like to create a sub VI that will accept two different enums as inputs, and the enums may have different dimensions, and will compare the selected string values of the two different enums and decide if the string values are equal.  So, if in enum #1, "Run Setup" is selected (regardless of the index value for "Run Setup" in that particular enum), and if "Run Setup" is selected in enum #2 (again, regardless of the index value for "Run Setup" in that particular enum), then I want the sub VI to output TRUE.
 
I attempted to attach my failed attempt at this sub VI (written in LV 8.2), so hopefully it gets posted and you can take a peek.  This sub VI doesn't like wiring just any enums as inputs, since the enums are "different" (they have different dimensions, for example).
 
Thanks to anyone who can help me out.
0 Kudos
Message 1 of 15
(4,631 Views)

Your VI seems to work fine. Enums are stricly typed so your subvi will only be able to work with those as inputs.

David

0 Kudos
Message 2 of 15
(4,619 Views)

Do you mean it works by itself?  It does work by itself for me, too, but I can't seem to use it as a sub VI.  Whenever I wire it up to use it, I get wiring conflicts.

Were you able to successfully use this sub VI in another VI?  Especially with different dimensioned enums coming in?

Thanks again for any help that can be provided.

0 Kudos
Message 3 of 15
(4,615 Views)

Its like I said. The subvi will only accept inputs from the caller if the enums are the same datatype. The enum is strictly typed.

Thats why you are getting the wiring conflicts.

David

0 Kudos
Message 4 of 15
(4,612 Views)
Can a sub VI be written that will accept any sized enums?  If it is not possible, because of the strict typing, then I will have to live with that.
 
Thanks, again, for the help.
0 Kudos
Message 5 of 15
(4,609 Views)

You can only wire like typed enums to each other.

If the do not match-up, LV will warn you by breaking the wire. This is good.

You could type cast the enums as U16 if you want to compare the numeric values.

The attached images shows what a sub-VI to compare the strings of the selected enums would look like.

It uses "format into string" before comparing the resulting strings.

I hope this helps,

 

Ben

Message Edited by Ben on 09-21-2006 11:46 AM

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 6 of 15
(4,606 Views)
Sorry, as far as I know you can't.
 
0 Kudos
Message 7 of 15
(4,601 Views)

Thanks to everyone who replied with some information.  I will just put the sub VI's code in the place of the sub VI itself.  I just wanted to do things quicker than having to write the same 3 function code over and over again.  I was hoping to boil it down to a single sub VI that will do the same thing.

Again, I appreciate all of the assistance.

0 Kudos
Message 8 of 15
(4,594 Views)
Don't write the same function 3 times.  That is what sub-vi's are for.  And it is better programming practice to use sub-vi's.  In your subvi, copy the enum and paste it in your main vi.  Then you can wire it from the main into the sub.  In the main, you can select the element you want to pass into your sub-vi.
- tbob

Inventor of the WORM Global
0 Kudos
Message 9 of 15
(4,584 Views)
I'll describe how I've done this kind of thing before  (sorry, no LV at my network PC so can't post code or screenshot).
 
Right-click an enum and select "Create-->Property Node".  Select the read-only "Strings[]" element from the list of properties, which returns an array of the enum's string values.  Then feed these strings and the enum's numeric value into 'Index Array' to retrieve the string corresponding to the current value of the enum.  Do the same for the other enum, and now you can check the enums for string equality rather than numeric equality.
 
-Kevin P.
ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
Message 10 of 15
(4,571 Views)