Date Literals Boolean Literals Nothing Summary of Literal Formats

29 To emphasize that this literal is of a different data type than a single-character string, note that this code causes a compile-time error if Option Strict is On : Wrong Dim MyChar As Char MyChar = A The error is: Option Strict On disallows implicit conversions from String to Char.

2.4.4 Date Literals

Literals of type Date are formed by enclosing a datetime string within number-sign characters. For example: Dim MyDate As Date MyDate = 11152001 3:00:00 PM Date literals in Visual Basic .NET code must be in the format mdyyyy , regardless of the regional settings of the computer on which the code is written.

2.4.5 Boolean Literals

The keywords True and False are the only Boolean literals. They represent the true and false Boolean states, respectively of course. For example: Dim MyBoolean As Boolean MyBoolean = True

2.4.6 Nothing

There is one literal that has no type: the keyword Nothing . Nothing is a special symbol that represents an uninitialized value of any type. It can be assigned to any variable and passed in any parameter. When used in place of a reference type, it represents a reference that does not reference any object. When used in place of a value type, it represents an empty value of that type. For numeric types, this is or 0.0 . For the String type, this is the empty string . For the Boolean type, this is False . For the Char type, this is the Unicode character that has a numeric code of . For programmer-defined value types, Nothing represents an instance of the type that has been created but has not been assigned a value.

2.4.7 Summary of Literal Formats

Table 2- 2 shows all of Visual Basic .NETs intrinsic types, as well as the format for writing literals of those types in programs. Table 2-2. Forming literals Data type Literal Example Boolean True , False Dim bFlag As Boolean = False Char C Dim chVal As Char = XC 30 Date Dim datMillen As Date = 01012001 Decimal D Dim decValue As Decimal = 6.14D Double Any floating point number, or R Dim dblValue As Double = 6.142 Dim dblValue As Double = 6.142R Integer An integral value in the range of type Integer -2,147,483,648 to 2,147,483,647, or I Dim iValue As Integer = 362 Dim iValue As Integer = 362I Dim iValue As Integer = H16AI hexadecimal Dim iValue As Integer = O552I octal Long An integral value outside the range of type Integer - 9,223,372,036,854,775,808 to -2,147,483,649, or 2,147,483,648 to 9,223,372,036,854,775,807, or L Dim lValue As Long = 362L Dim lValue As Long = H16AL hexadecimal Dim lValue As Long = O552L octal Short S Dim shValue As Short = 362S Dim shValue As Short = H16AS hexadecimal Dim shValue As Short = O552S octal Single F Dim sngValue As Single = 6.142F String Dim strValue As String = This is a string Note the following facts about forming literals in Visual Basic .NET: • There is no way to represent a literal of type Byte. However, this doesnt mean that literals cannot be used in situations where type Byte is expected. For example, the following code is fine: Dim MyByte As Byte = 100 • Even though the Visual Basic .NET compiler considers 100 to be of type Integer in this example, it recognizes that the number is small enough to fit into a variable of type Byte. • Types not shown in Table 2- 2 cant be expressed as literals. 31

2.5 Types