Using Literals

A literal is a textual representation of a particular value of a data type.
Visual Basic supplies a set of literal type characters, which you can use to force a literal to assume a data type other than the one its form indicates. You do this by appending the character to the end of the literal. The following table shows the available literal type characters with examples of usage.
Literal type character Data type Example
S Short I = 347S
I Integer J = 347I
L Long K = 347L
D Decimal X = 347D
F Single Y = 347F
R Double Z = 347R
US UShort L = 347US
UI UInteger M = 347UI
UL ULong N = 347UL
C Char Q = "."C
No literal type characters exist for the Boolean, Byte, Date, Object, SByte, or String data types, or for any composite data types such as arrays or structures.
Literals can also use the identifier type characters (%, &, @, !, #, $), as can variables, constants, and expressions. However, the literal type characters (S, I, L, D, F, R, C) can be used only with literals.
In all cases, the literal type character must immediately follow the literal value.

Literals are values that you assign to data. In some cases, we need to add a suffix behind a literal so that VB can handle the calculation more accurately. For example, we can use num=1.3089# for a Double type data.Literals can also use the identifier type characters (%, &, @, !, #, $), as can variables, constants, and expressions



Suffix
Data Type
&
Long
!
Single
#
Double
@
Currency
In addition, we need to enclose string literals within two quotations and date and time literals within two # sign. Strings can contain any characters, including numbers. The following are few examples:
memberName="Turban, John."
TelNumber="1800-900-888-777"
LastDay=#31-Dec-00#
ExpTime=#12:00 am#
 


A character literal is entered using a single character string suffixed with a C.

Dim theLetterA As Char = "A"C