A constant is the amount that cannot be changed during the running of the program. VB. NET has three constants: Direct Volume, user-defined symbol constant, and system-defined symbol constant. The last two are symbol constants.
1. Direct Volume
A direct volume is also called a literal constant. It is short for a direct constant. It refers to the amount that appears directly in the program as a value. For example, 123 or 12.8. The value of a direct volume directly reflects the Data Type of the volume. You can also explicitly describe the data type of the direct volume with the Type Operator after the value. Here are some examples:
123-integer 123 &-long integer 123.8-single precision Floating Point decimal form)
1.26E2-single-precision floating point index form) 690D3-double-precision floating point number
"Abc", "Hello! "-True, False-logical constant #3-20-2003 #-date constant
In addition to decimal constants, numeric constants include octal constants and hexadecimal constants, respectively. For example, & O23 is octal value 23 and & H2C is hexadecimal value 2C.
2. User-Defined symbolic Constants
A symbolic constant is a constant represented by an identifier. It is easy to maintain programs.
Constant definition Syntax:
Const symbol constant name [As type name] = expression
Defines a constant specified by the symbolic constant name. Its type is the data type given by the type name, and its value is the value of the expression. If the As type name is omitted, the constant data type is determined by the Data Type of the expression value. For example:
Const PI = 100' indicates that the type name is omitted. The PI is Double type based on the expression value.
Const Name As String = "Zhang Hua" 'defines a String constant with a value of "Zhang Hua"
The Const Area = PI * 5*5 'expression can use a defined symbolic constant.
You can define multiple constants in a row. For example:
Const PI = 3.14159, Name As String = "Zhang Hua", Area = PI * 5*5
3. System-defined symbolic Constants
Symbolic constants defined by the system have specific meanings and can be directly referenced in programs. The names of system-defined symbolic constants are often named in case-insensitive manner based on their meanings. Table 3-2 lists some common system-defined symbolic constants.
Table 3-2 system symbol Constants
Description of constant name values
VbCrLf Chr (13) + Chr (10) carriage return line break
VbCr Chr (13) carriage return
VbCr Chr (10) line feed
VbNewLine Chr (13) + Chr (10) carriage return line break
VbNullChar Chr (0) NULL Character
VbNullString a null string with a length of 0
VbTab Chr (9) Tab character
VbBack Chr (8) [Backspace] characters.
| BibliographyPrevious sectionNext section |