Wednesday, June 17, 2015

C# VBA Side by Side using Enumerations

An enumeration is a set of named constants whose values are generally related.  In Excel VBA, an enumeration statement (Enum) is made in the Declarations section of a standard or public class module. In C#, an enumeration is defined directly within a namespace.  By default, the first enumerator is assigned the value of 0 and the value of each successive enumerator is increased by 1.

Excel VBA

Tip: IF the enum description, contains blanks or special characters, then surround the enum name with brackets ([ ]).


Public Enum OfficeProduct
    Access2007Only = 1
    [MSAccess95-2003]
    Excel2007Only
    [MSExcel95-2003]
    [XML]
End Enum

C#


public enum OfficeProduct {
       Access2007Only=1,
       MSAccess95_2003=2,
       Excel2007Only=3,
       MSExcel95_2003=4,
       XML=5};

No comments: