Hi all, int a = obj."A" int b = obj."B" int result = a + b obj."MyAttribute" = result // Fails here
atroq - Thu Oct 14 07:47:09 EDT 2010 |
Re: How to convert from Integer to enumeration to assign value to DXL attribute
There is no simple conversion from integer to enumeration (or at least I could not think of one ..). An integer attribute is just an integer value, but enumerated attribute is kind of array of values, each of which have a string value and an integer "related number". The code below presumes that your related numbers are as you have described them from 0 to 4 and then display the corresponding string value for type of the DXL attribute. int a = obj."A" int b = obj."B" int result = a + b AttrDef ad = find(current Module, attrDXLName) AttrType at = ad.type obj.attrDXLName = at.strings[result] |
Re: How to convert from Integer to enumeration to assign value to DXL attribute SystemAdmin - Thu Oct 14 08:19:35 EDT 2010
There is no simple conversion from integer to enumeration (or at least I could not think of one ..). An integer attribute is just an integer value, but enumerated attribute is kind of array of values, each of which have a string value and an integer "related number". The code below presumes that your related numbers are as you have described them from 0 to 4 and then display the corresponding string value for type of the DXL attribute. int a = obj."A" int b = obj."B" int result = a + b AttrDef ad = find(current Module, attrDXLName) AttrType at = ad.type obj.attrDXLName = at.strings[result] |
Re: How to convert from Integer to enumeration to assign value to DXL attribute
In many programming languages, enums are have a literal value and an ordinal value. Both must be unique. string strings[ NO_OF_ENUM_MEMBERS ]; // required & unique int colors [ NO_OF_ENUM_MEMBERS ]; // optional & may overlap int values [ NO_OF_ENUM_MEMBERS ]; // optional & may overlap
// C syntax
typedef enum {RED, BLUE, GREEN} ColorType;
strings[0] = "RED"; strings[1] = "BLUE"; strings[2] = "GREEN";
put(colorSkip, "RED", 0);
put(colorSkip, "BLUE", 1);
put(colorSkip, "GREEN", 2);
string someColorLiteral = "BLUE";
int someColorOrdinal = -1;
// The below would find key "BLUE" and populate someColorOrdinal
// with 1.
find(colorSkip, someColorLiteral, someColorOrdinal);
int iBLUE = 1;
if (someColorOrdinal != iBLUE) {
}
|