Visual Basic 中的数据类型Data Types in Visual Basic

编程元素的数据类型是指可以保留的数据种类以及相应类型数据的存储方式。The data type of a programming element refers to what kind of data it can hold and how it stores that data. 数据类型适用于所有可以存储到计算机内存中或参与表达式求值的值。Data types apply to all values that can be stored in computer memory or participate in the evaluation of an expression. 每个变量、文本、常量、枚举、属性、过程参数、过程自变量和过程返回值都有对应的数据类型。Every variable, literal, constant, enumeration, property, procedure parameter, procedure argument, and procedure return value has a data type.

已声明的数据类型Declared Data Types

可以使用声明语句定义编程元素,并使用 As 子句指定其数据类型。You define a programming element with a declaration statement, and you specify its data type with the As clause. 下表列出了用于声明各种元素的语句。The following table shows the statements you use to declare various elements.

编程元素Programming element 数据类型声明Data type declaration
变量Variable 使用 Dim 语句In a Dim Statement

Dim amount As DoubleDim amount As Double

Static yourName As StringStatic yourName As String

Public billsPaid As Decimal = 0Public billsPaid As Decimal = 0
文本Literal 含文本类型字符;请参阅类型字符中的“文本类型字符”With a literal type character; see "Literal Type Characters" in Type Characters

Dim searchChar As Char = "." CDim searchChar As Char = "." C
常数Constant 使用 Const 语句In a Const Statement

Const modulus As Single = 4.17825FConst modulus As Single = 4.17825F
枚举Enumeration 使用 Enum 语句In an Enum Statement

Public Enum colorsPublic Enum colors
属性Property 使用 Property 语句In a Property Statement

Property region() As StringProperty region() As String
过程参数Procedure parameter 使用 Sub 语句Function 语句Operator 语句In a Sub Statement, Function Statement, or Operator Statement

Sub addSale(ByVal amount As Double)Sub addSale(ByVal amount As Double)
过程自变量Procedure argument 在调用的代码中;每个自变量都是一个已声明的编程元素或包含已声明元素的表达式In the calling code; each argument is a programming element that has already been declared, or an expression containing declared elements

subString = Left( inputString , 5 )subString = Left( inputString , 5 )
过程返回值Procedure return value 使用 Function 语句Operator 语句In a Function Statement or Operator Statement

Function convert(ByVal b As Byte) As StringFunction convert(ByVal b As Byte) As String

有关 Visual Basic 数据类型的列表,请参阅数据类型For a list of Visual Basic data types, see Data Types.

请参阅See also