Enum 语句

目录
索引 🔎︎

# Enum 语句 [VBA]

定义枚举或非 UNO 常量组。枚举是值的列表, 可方便编程并简化代码逻辑检查。

This constant, function or object is enabled with the statement Option VBASupport 1 placed before the executable program code in a module.

### 语法:

           Enum list_name
               ' Object Statement block
           End Enum ' list_name

## 参数:

在给定的枚举中, 将逻辑上相互关联的值组合在一起。

### 示例:

           Option VBASupport 1
           Private Enum _WindowManager
               W1ND0WS = 1 ' Windows
               OS2PM = 2 ' OS/2 Presentation Manager
               MACINTOSH = 3 ' Macintosh
               MOTIF = 4 ' Motif Window Manager / Unix-like
               OPENLOOK = 5 ' Open Look / Unix-like
           End Enum
           Public Function WindowManager() As Object
               WindowManager = _WindowManager
           End Function ' <library>.<module>.WindowManager.XXX

枚举值将呈现为「Long」数据类型。Basic 函数是枚举的公共访问器。枚举名称和值的名称在库中和模块之间必须是唯一的。

## 用法:

显示 WindowManager 分组常量值:

           Dim winMgr As Object : winMgr = <library>.<module>.WindowManager
           With winMgr
               Print .MACINTOSH, .MOTIF, .OPENLOOK, .OS2PM, .W1ND0WS
           End With

Enumerations can be extended to other data types using Type statement definitions. Calling Python Scripts from Basic illustrates that mechanism.

相关主题

Const 语句, 常量

Option VBASupport 语句

With 语句