O'Reilly logo

Programming Visual Basic 2008 by Tim Patrick

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Literals

The quickest way to include values of a particular data type in your Visual Basic code is to use a literal. You've already seen literals in action in this book. Chapter 1 included a literal in its sample project.

MsgBox("Hello, World!")

This call to the MsgBox function includes a String literal. String literals always appear within a set of double quotes. Most numeric literals appear with a data-type-defining character on the end of the literal, but there are other variations. Table 6-6 lists the different literal values you can include in your code.

Table 6-6. Literals supported by Visual Basic

Literal type

Example

Description

Boolean

True

The Boolean data type supports two literal values: True and False.

Char

"Q"c

Single-character literals appear in double quotes with a trailing character c. A literal of type Char is not the same as a single-character literal of type String.

Date

#11/7/2005#

Date or time literals appear between a set of number signs. You can include dates, times, or a combination of both. The date or time values can be in any format recognized by Windows, although Visual Studio may reformat your date literal for conformity with its own standards.

Decimal

123.45D

123.45@

Floating-point values of type Decimal are followed by a capital D, or the character @.

Double

123.45R

123.45#

Floating-point values of type Double are followed by a capital R, or the character #. Also, if you use a numeric literal with a decimal portion, but with no trailing data type character, that literal ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required