The Enum class lets you map strings to C or C++ enum values that can be used in Excel. It is similar to the AddIn class.

static Enum enum_freq(
    Name("FREQ")
    .Item("Annual", 1, "once per year")
    .Item("SemiAnnual", 2, "twice per year")
    .Item("Quarterly", 4, "four times per year")
    .Item("Monthly", 12, "twelve times per year")
    .Category("Enumerations")
    .Description("Payment frequency.")
);

To access the values in Excel use ENUM(). For example, ENUM("FREQ", "SemiAnnual") will return 2. Enumeration names are canonicalized to be keyed off of the capital letters in the name. You can also use ENUM("FREQ", "SA"), ENUM("freq", "sa"), or ENUM("fReQ", "SemiAnn") to get the same result. If the second argument is a numerical value, ENUM() just returns that.

If you call ENUM() with one argument it will return all of the associated enumeration values in a three column array. The first column is the long name, the second column is the value, and the third column is the description. Look into Alt-D-L to figure out why this is useful.

If you call ENUM() with no arguments it returns a list of enumerations.

Last edited Aug 21, 2013 at 1:24 AM by keithalewis, version 5

Comments

No comments yet.