常量和枚举 (Visual Basic)Constants and Enumerations (Visual Basic)

Visual Basic 为开发人员提供了许多预定义的常量和枚举。Visual Basic supplies a number of predefined constants and enumerations for developers. 常量存储在应用程序的整个执行过程中保持不变的值。Constants store values that remain constant throughout the execution of an application. 枚举提供了使用相关常量集以及将常量值与名称相关联的一个便捷方法。Enumerations provide a convenient way to work with sets of related constants, and to associate constant values with names.

常量Constants

条件编译常量Conditional Compilation Constants

下表列出了可用于条件编译的预定义常量。The following table lists the predefined constants available for conditional compilation.

常量Constant 描述Description
CONFIG Configuration Manager中 "活动解决方案配置" 框的当前设置相对应的字符串。A string that corresponds to the current setting of the Active Solution Configuration box in the Configuration Manager.
DEBUG 可在 "项目属性" 对话框中设置的 Boolean 值。A Boolean value that can be set in the Project Properties dialog box. 默认情况下,项目的调试配置定义 DEBUGBy default, the Debug configuration for a project defines DEBUG. 定义 DEBUG 时,Debug 类方法将生成输出到 "输出" 窗口。When DEBUG is defined, Debug class methods generate output to the Output window. 如果未定义此方法,则不会编译 Debug 类方法,也不会生成任何调试输出。When it is not defined, Debug class methods are not compiled and no Debug output is generated.
TARGET 一个字符串,表示项目的输出类型或命令行目标选项的设置。A string representing the output type for the project or the setting of the command-line -target option. TARGET 的可能值为:The possible values of TARGET are:

-Windows 应用程序的 "winexe"。- "winexe" for a Windows application.
-适用于控制台应用程序的 "exe"。- "exe" for a console application.
-类库的 "库"。- "library" for a class library.
-模块的 "module"。- "module" for a module.
-可在 Visual Studio 集成开发环境中设置 -target选项。- The -target option may be set in the Visual Studio integrated development environment. 有关详细信息,请参阅-target (Visual Basic)For more information, see -target (Visual Basic).
TRACE 可在 "项目属性" 对话框中设置的 Boolean 值。A Boolean value that can be set in the Project Properties dialog box. 默认情况下,项目的所有配置都定义 TRACEBy default, all configurations for a project define TRACE. 定义 TRACE 时,Trace 类方法将生成输出到 "输出" 窗口。When TRACE is defined, Trace class methods generate output to the Output window. 如果未定义此方法,则不会编译 Trace 类方法,也不会生成任何 Trace 输出。When it is not defined, Trace class methods are not compiled and no Trace output is generated.
VBC_VER 一个表示 Visual Basic 版本的数字,以格式。A number representing the Visual Basic version, in major.minor format.

调用打印和显示功能时,可以在代码中使用以下常量来替换实际值。When you call print and display functions, you can use the following constants in your code in place of the actual values.

常量Constant 描述Description
vbCrLf 回车符/换行符的组合。Carriage return/linefeed character combination.
vbCr 回车符。Carriage return character.
vbLf 换行符。Linefeed character.
vbNewLine 换行符。Newline character.
vbNullChar 空字符。Null character.
vbNullString 与零长度字符串("")不同;用于调用外部过程。Not the same as a zero-length string (""); used for calling external procedures.
vbObjectError 错误号。Error number. 用户定义的错误号应当大于此值。User-defined error numbers should be greater than this value. 例如:For example:

Err.Raise(Number) = vbObjectError + 1000
vbTab 制表符。Tab character.
vbBack Backspace 字符。Backspace character.
vbFormFeed 不在 Microsoft Windows 中使用。Not used in Microsoft Windows.
vbVerticalTab 在 Microsoft Windows 中不起作用。Not useful in Microsoft Windows.

枚举Enumerations

下表列出并描述了 Visual Basic 提供的枚举。The following table lists and describes the enumerations provided by Visual Basic.

枚举Enumeration 描述Description
AppWinStyle 指示在调用 Shell 函数时用于被调用程序的窗口样式。Indicates the window style to use for the invoked program when calling the Shell function.
AudioPlayMode 指示在调用音频方法时如何播放声音。Indicates how to play sounds when calling audio methods.
BuiltInRole 指示在调用 IsInRole 方法时检查的角色类型。Indicates the type of role to check when calling the IsInRole method.
CallType 指示在调用 CallByName 函数时调用的过程类型。Indicates the type of procedure being invoked when calling the CallByName function.
CompareMethod 指示当调用比较函数时如何比较字符串。Indicates how to compare strings when calling comparison functions.
DateFormat 指示在调用 FormatDateTime 函数时如何显示日期。Indicates how to display dates when calling the FormatDateTime function.
DateInterval 指示当调用与日期相关的函数时如何确定日期间隔并设置其格式。Indicates how to determine and format date intervals when calling date-related functions.
DeleteDirectoryOption 指定当要删除的目录中含有文件或目录时应采取的操作。Specifies what should be done when a directory that is to be deleted contains files or directories.
DueDate 指示在调用财务方法时付款何时到期。Indicates when payments are due when calling financial methods.
FieldType 指示文本字段是分隔的还是固定宽度的。Indicates whether text fields are delimited or fixed-width.
FileAttribute 指示当调用文件访问函数时要使用的文件特性。Indicates the file attributes to use when calling file-access functions.
FirstDayOfWeek 指示在调用与日期相关的函数时使用的每周的第一天。Indicates the first day of the week to use when calling date-related functions.
FirstWeekOfYear 指示在调用与日期相关的函数时使用的每年的第一周。Indicates the first week of the year to use when calling date-related functions.
MsgBoxResult 指示在消息框上按下了哪个按钮,由 MsgBox 函数返回。Indicates which button was pressed on a message box, returned by the MsgBox function.
MsgBoxStyle 指示调用 MsgBox 函数时显示的按钮。Indicates which buttons to display when calling the MsgBox function.
OpenAccess 指示调用文件访问函数时如何打开文件。Indicates how to open a file when calling file-access functions.
OpenMode 指示调用文件访问函数时如何打开文件。Indicates how to open a file when calling file-access functions.
OpenShare 指示调用文件访问函数时如何打开文件。Indicates how to open a file when calling file-access functions.
RecycleOption 指定文件是应永久删除还是放入回收站。Specifies whether a file should be deleted permanently or placed in the Recycle Bin.
SearchOption 指定是搜索所有目录还是仅搜索顶级目录。Specifies whether to search all or only top-level directories.
TriState 指示 Boolean 值或在调用数字格式设置函数时是否应使用默认值。Indicates a Boolean value or whether the default should be used when calling number-formatting functions.
UICancelOption 指定当用户在操作过程中单击 "取消" 时应执行的操作。Specifies what should be done if the user clicks Cancel during an operation.
UIOption 指定在复制、删除或移动文件或目录时是否显示进度对话框。Specifies whether or not to show a progress dialog when copying, deleting, or moving files or directories.
VariantType 指示由 VarType 函数返回的变量对象的类型。Indicates the type of a variant object, returned by the VarType function.
VbStrConv 指示调用 StrConv 函数时要执行的转换类型。Indicates which type of conversion to perform when calling the StrConv function.

另请参阅See also