Hi
If I call str2enum, e.g like this,
NoYes ny;
ny = str2enum(ny, 'badvalue');
what value will ny get? I can see in the debugger that it does not have Yes, not No. It is just blank. But I have not found a working way to identify this in a if clause.
(!ny) does not work
(ny==null) does not work
Any ideas?
*This post is locked for comments
So basically this works:
static void Adtest_enum(Args _args) { NoYesCombo n; ; if (!enum2str(str2Enum(n, 'bad'))) { info('bad enum'); } }
Usually all enum values have nonblank labels (if not then it's not good at all as you cannot use a blank enum label in a query range) so you can call enum2str(ny) and check if it returns a blank string. If it does then the enum variable definitely holds an invalid value. Internally in case of an incorrect conversion AX assigns a value of 255 to an enum variable (in MorphX a maximum enum value that you can use is 250) but this is kind of... undocumented so enum2str() is a preferable way to check if a preceding str2enum() call returned a valid enum value.
Try this:
static void Test(Args _args)
{
ABC abc;
str test;
;
test = "A";
if(str2Enum(abc,test) == ABC::A)
{
print "test";
pause;
}
}
Hi Jonas,
Are your intentions to just see if an enum exists? If so use this global enum method instead of str2enum.
static void Job35(Args _args)
{
NoYes ny;
;
ny = enumName2Id("Baddy");
if(ny > 0)
info("Good enum");
else
info("Bad enum");
}
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156