HChandler Posted October 4, 2008 Report Share Posted October 4, 2008 Say I have a strictly typecast enum that I want to pass into a more generic vi that (for instance) compares a string to the enumeration strings to return the index of said string, and signals if not present. It would be great if the vi could take in the strictly typecast enum and still be generic enough to use with ANY enumerated type. Will settle for downcast outside of vi. Thanks Quote Link to comment
Francois Normandin Posted October 4, 2008 Report Share Posted October 4, 2008 QUOTE (HChandler @ Oct 3 2008, 11:56 AM) Say I have a strictly typecast enum that I want to pass into a more generic vi that (for instance) compares a string to the enumeration strings to return the index of said string, and signals if not present.It would be great if the vi could take in the strictly typecast enum and still be generic enough to use with ANY enumerated type. Will settle for downcast outside of vi. Thanks You can cast to a more generic class inside or outside a subVI. See attached picture. http://lavag.org/old_files/monthly_10_2008/post-10515-1223053663.png' target="_blank"> Quote Link to comment
HChandler Posted October 4, 2008 Author Report Share Posted October 4, 2008 I'm not sure you're getting what I mean (or vice versa) Here're a couple of vi's that explain what I'm trying to do. Sorry no pictures, my screen capture (printkey 2000) bombed out. Quote Link to comment
ned Posted October 4, 2008 Report Share Posted October 4, 2008 QUOTE (HChandler @ Oct 3 2008, 01:37 PM) I'm not sure you're getting what I mean (or vice versa)Here're a couple of vi's that explain what I'm trying to do. Sorry no pictures, my screen capture (printkey 2000) bombed out. Convert your enumeration to a variant and pass that in. Use the Variant library (vi.lib\Utility\VariantDataType\VariantType.lvlib) functions to get the strings for that enumeration. The specific VI you want is probably GetNumericInfo. Quote Link to comment
Francois Normandin Posted October 4, 2008 Report Share Posted October 4, 2008 QUOTE (HChandler @ Oct 3 2008, 01:37 PM) I'm not sure you're getting what I mean (or vice versa)Here're a couple of vi's that explain what I'm trying to do. Sorry no pictures, my screen capture (printkey 2000) bombed out. I'm working on LV8.6 so I won't put the VI... but your example doesn't work either way (see error message on FP). You don't have the same datatype. You're going to need to use references to do this. The Stacked Sequence I show will do it for both cases, as long as you use a reference to your control. http://lavag.org/old_files/monthly_10_2008/post-10515-1223056616.png' target="_blank"> EDIT: ned has a point. You can extract your strings from Variant, but not convert it to an empty enum. Quote Link to comment
HChandler Posted October 4, 2008 Author Report Share Posted October 4, 2008 Oh dang! I guess I should have checked to see if it really worked. Unfortunately I was focusing on another problem. Your example works MUCH better than mine but still requires the input of the vi to be strictly typedef-ed. What I was really trying to do is have a vi that you could pass any old enum (including strictly typedef), and a string and get the position of the string in the enum ( or an error if not). What I really would like to know is if it's possible to pass a strict typedef enum into a non-typed enum. Thanks Quote Link to comment
Francois Normandin Posted October 4, 2008 Report Share Posted October 4, 2008 QUOTE (HChandler @ Oct 3 2008, 02:44 PM) Oh dang! I guess I should have checked to see if it really worked. Unfortunately I was focusing on another problem. Your example works MUCH better than mine but still requires the input of the vi to be strictly typedef-ed. What I was really trying to do is have a vi that you could pass any old enum (including strictly typedef), and a string and get the position of the string in the enum ( or an error if not). What I really would like to know is if it's possible to pass a strict typedef enum into a non-typed enum. Thanks Check out one post up... I edited it with the VI saved in version 8.2. However, you'll need OpenG. Do you have the librairies installed? If not, get VIPM and install the packages. Quote Link to comment
HChandler Posted October 4, 2008 Author Report Share Posted October 4, 2008 I just realized that I have not updated my profile. I AM using Version 8.6! Thanks for everything. Quote Link to comment
Aristos Queue Posted October 4, 2008 Report Share Posted October 4, 2008 Use the Type Cast node to cast your refnum to an int32. Then use the Type Cast node again to cast that int32 to any refnum type you desire. Warning: After you do this, when you pass the resulting refnum to various functions in LV, you may or may not crash LV. It depends upon the operation. After all, you're giving a function a reference to one thing that is actually a reference to something else. Some work, some don't. Caveat emptor. Quote Link to comment
Yair Posted October 5, 2008 Report Share Posted October 5, 2008 QUOTE (HChandler @ Oct 3 2008, 08:37 PM) Sorry no pictures, my screen capture (printkey 2000) bombed out. Maybe you should have used a better tool . QUOTE (Aristos Queue @ Oct 3 2008, 11:49 PM) Use the Type Cast node to cast your refnum to an int32. Then use the Type Cast node again to cast that int32 to any refnum type you desire. Welcome to the dark side, Stephen. All these years around those supersecretprivate hackers must have poisoned your mind. P.S. Any reason for taking a detour through the int instead of casting directly to the desired class? Quote Link to comment
Aristos Queue Posted October 6, 2008 Report Share Posted October 6, 2008 QUOTE (Yair @ Oct 4 2008, 01:25 PM) P.S. Any reason for taking a detour through the int instead of casting directly to the desired class? Because many of the class refnums will refuse to cast to each other (wires break) in order to prevent exactly this sort of thing from happening by accident. You really have to think about to consciously decide to do this. Quote Link to comment
ragglefrock Posted October 7, 2008 Report Share Posted October 7, 2008 You can also use the Scan from String primitive to get the index of a particular enum string. This will work with any enum already, so there's no reason to build a generic subVI for it. Quote Link to comment
Francois Normandin Posted October 7, 2008 Report Share Posted October 7, 2008 QUOTE (ragglefrock @ Oct 6 2008, 12:15 PM) You can also use the Scan from String primitive to get the index of a particular enum string. This will work with any enum already, so there's no reason to build a generic subVI for it. This is absolutely true. However the initial question was to get it inside a SubVI. (But I see your point: Why wrap it up in a subVI if it works with a single drop from a palette? :thumbup: ) Quote Link to comment
HChandler Posted October 7, 2008 Author Report Share Posted October 7, 2008 I did not know you could do that with scan string. But then I would not have learned so much about living without pointers :thumbup: . QUOTE (normandinf @ Oct 6 2008, 12:04 PM) This is absolutely true. However the initial question was to get it inside a SubVI. (But I see your point: Why wrap it up in a subVI if it works with a single drop from a palette? :thumbup: ) Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.