10-03-2017 05:27 PM
I know enum value can be set using Scan From String function during run time. Also I know if I have enums with same values, I can build them into an array and set the values in a for loop using the Scan From String function. I have enums with different values, if I build them into an array, data types are converted and the value property becomes variant data type, then I don't know how it can be handled. I tried to use To More Specific Class, it doesn't help. Any suggestions? Thanks.
Solved! Go to Solution.
10-04-2017 04:29 AM
@guangdew1 wrote:
Any suggestions? Thanks.
Your explaining what you've tried, but not what you are trying to achieve.
Scan From String doesn't really set an enum value, it creates a new variable with a value. Adding enum values to an array, converts the enums to integers. So I suppose you're talking about enum references? If you get variant values, you can convert them to integers (Variant To Data), or to an enum.
I think you're walking on thin ice here. Doing this stuff wrong can seriously harm your LabVIEW experience.
You know about typedefs? Not knowing about them and working with enums is a very bad situation...
10-04-2017 09:27 AM
I may not have made myself clear, the attached vi further explained it. This is LabVIEW 2013, if you want to have lower version, let me know. The vi can be run if you disable the broken part.
I cannot post a snippet, everything related with references are messed up if I do.
10-04-2017 09:28 AM
Forgot the attachment.
10-04-2017 09:42 AM
This Nugget I wrote on Using Control references may help you.
One example included in that nugget shows how to use a trial and error approach to casting the reference to the correct type.
Also be aware that using Type-defined Enums will help out.
Ben
10-04-2017 09:43 AM
That's exactly what I was thinking you where doing.
Since the Scan From String works on the enum strings, and doesn't except variants, you're on your own. Get the enum strings from it's Strings[] property, and compare them:
Note this isn't exactly the same as Scan From String. Scan From String matches the longest string in the enum, and excepts text behind the input string. So "yes sir" would also match yes. The search will succeed only if there is an exact match. You could change this of course. The concept should be clear.
10-04-2017 12:20 PM
Hi Ben,
I'm reading your nugget, what I want to do is just like your concern, set default behavior of an executable.
You mentioned to make enum into typedef, I tried to make them either typedef or strict typedef, but I don't see it helps, could you explain?
Thanks.
10-04-2017 12:51 PM
@guangdew1 wrote:
Hi Ben,
I'm reading your nugget, what I want to do is just like your concern, set default behavior of an executable.
You mentioned to make enum into typedef, I tried to make them either typedef or strict typedef, but I don't see it helps, could you explain?
Thanks.
At the time I wrote that Nugget, we were running LV 8.0 or so and did have nearly as many options or tool-kits as we do now. I linked that Nugget to show you how a value for an unknown type control an be set. What you should do is scan the replies to that nugget and find the various other tools-kits that are available. I THNK "Moore-good ideas" may have a complete tool-kit. It may also be built into the OpenG Toolkit.
re: Type definitions...
I use then anytime I have an enum or a cluster that is used more than one place. The type definition will update all instances of the widget when I modify it. I wrote another Nugget on Type defs that you can find here.
Ben
10-04-2017 01:05 PM - edited 10-04-2017 01:05 PM
If you mix enums you need to use the numerical representation instead.
/Y
10-04-2017 01:11 PM
@Yamaeda wrote:
If you mix enums you need to use the numerical representation instead.
/Y
That example is just ONE of the newer features available in modern versions of LabVIEW that I alluded too.
Those functions can be found on a variant sub-palette.
Just like working in a machine shop, it is a good idea to get an idea about ALL of the tools in in your tool-box otherwise you will find yourself trying to drive a screw with a hammer.
But in fairness to my old nugget, back then we only had hammers and screwdrivers had not yet been invented. (smiley-wink).
Ben