I have recently come across numeric literals such as 10! and 50# in Visual Basic programs. Could anyone tell me what these punctuation marks mean?
Asked
Active
Viewed 1.3k times
3 Answers
36
They are called type declaration characters. This article has more information.
% Integer
& Long
! Single
# Double
$ String
@ Currency

onedaywhen
- 55,269
- 12
- 100
- 138

Michael Baker
- 3,338
- 26
- 29
-
Really? 123$ is the same as "123"? Wow - I never knew that! – teedyay Oct 08 '10 at 08:45
-
1This is true only for variable names, not for constant literals! – nothrow Oct 08 '10 at 08:54
-
Yeah, I'd seen them in that context, but that didn't seem to be what the question was about... – teedyay Oct 08 '10 at 09:02
-
@Michael Baker> you misunderstood the article. They AREN'T attached to literal, but to the variable name, and is used like `Dim x as String` => `Dim x$` – nothrow Oct 08 '10 at 09:42
-
According the article: "Literals can also use the identifier type characters as can variables, constants, and expressions." Can you elaborate? – Michael Baker Oct 08 '10 at 09:54
-
Has the hyperlink been edited? Within seconds I opened the same link twice and end up at two different articles! This one (http://support.microsoft.com/kb/191713) relates to VB6 and doesn't mention literals. This one (http://msdn.microsoft.com/en-us/library/s9cz43ek(v=VS.71).aspx) talks about literals but relates to VB.NET. – onedaywhen Oct 08 '10 at 10:01
-
@Michael Baker: I rolled back. The article about literals only applies to VB.NET and the question has only ever had the VB6 tag. – onedaywhen Oct 08 '10 at 10:26
-
1In VB6 you can use some of these characters - %&!#@ - with numeric literals to define the type. It's similar to the use in VB.Net although only the symbols are available, not the letters, and also a VB6 `Integer` is not the same as a VB.Net `Integer`. I'm just looking for a VB6 web link for you... – MarkJ Oct 08 '10 at 11:32
-
Normally, you'd see these attached to (numeric) literals in one of two places: is Const statements (since compiler constants are just replacement text, they can't have a "real" type); or when coercing a literal to Long, Double or Currency to avoid overflow (although I always preferred an explicit Ctype for maintainability). – Stan Rogers Oct 08 '10 at 17:33
16
Using these characters specifies the data type of a numeric literal.
I thought this would be covered in the VB6 manual online but I can't find it.
However I just proved it with the TypeName function in the VB6 IDE Immediate Window:
? typename(10!)
Single
?typename(10#)
Double
?typename(10%)
Integer
?typename(10&)
Long
?typename(10@)
Currency
PS Be aware that a VB6 Integer
is 2 bytes, -32,768 to 32,767.

MarkJ
- 30,070
- 5
- 68
- 111
4
****Here is a Cheat Sheet for DataTypes ****
Variable End with:
$ : String
% : Integer (Int16)
& : Long (Int32)
! : Single
# : Double
@ : Decimal
Start with:
&H : Hex
&O : Octal
Comparison between VB and VB.Net (reference)
Visual Studio .Net added Literal Types (reference)
Value End with: (For more complete list, refer the the reference)
S : Short (Int16)
I : Integer (Int32)
L : Long (Int64)
F : Single
R : Double
D : Decimal

Gerhard Powell
- 5,965
- 5
- 48
- 59