Click here to Skip to main content
12,758,462 members (31,500 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


7 bookmarked
Posted 17 Aug 2012

How to declare a variable in VB.NET without using the As type

, 17 Aug 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
How to declare variables in VB.NET without using the As type.


This article is about how to declare variables in VB.NET without using the As type.

Type Specifying Characters

A type character following a non-escaped identifier (with no whitespace between them) denotes the type of the identifier. You can use it in place of the As type portion of declaration, for example the following declaration:

Dim str$ 

'str is a variable name and $ indicates as String Type.
'the above declaration is as same thing as following.
Dim str As String

Type character also detracts from readability. If you use them be sure that if the declaration includes a type character, the character agrees with the type specified in the declaration itself; otherwise, a compiler time error occurs if your declaration omits the type. The complier will insert the type character implicitly substituted as the type of the declaration. The following syntax lists the type characters available in VB.NET (there is no type character for Byte or Short).

Type Character Character

Example of declaration

Dim num%       'num is variable of Integer type declared.

While declared variable we can also initialize a value to it.


Also we can declare multiple variables at a time.

Dim num, n%        'num & n is variable of Integer type declared.

We can also initialize it at the time of declaration.

Dim num = 250, n = 670,val%      'num,n & val is variable of Integer type.

Different types can be declare at a time.

Dim number = 180%, str$, salary@
'number is variable of Integer Type & initialized,
'str is variable of String Type, Salary is variable of Decimal Type

All types of declaration can be viewed as follows.

Dim number%    'number is variable of Integer Type.
Dim num&       'num is variable of Long Integer Type.
Dim salary@    'salary is variable of Decimal Type.
Dim amount!    'amount is variable of Single Type.
Dim rate#      'rate is variable of Double Type.
Dim name$      'name is variable of String Type.


No spaces are allowed within a variable name and type character. Syntax: Dim [variableName] space [Type Character].


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Patil Kishor
Software Developer
India India
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralGood to know Pin
DejaVu832-Sep-13 20:56
memberDejaVu832-Sep-13 20:56 
Questiondont likey... Pin
Simon_Whale28-Aug-12 4:30
memberSimon_Whale28-Aug-12 4:30 
Question[My vote of 1] Sorry, but no. Pin
crb900020-Aug-12 9:27
membercrb900020-Aug-12 9:27 
GeneralMy vote of 1 Pin
rctaubert18-Aug-12 8:57
memberrctaubert18-Aug-12 8:57 
GeneralMy vote of 2 Pin
Klaus Luedenscheidt17-Aug-12 18:57
memberKlaus Luedenscheidt17-Aug-12 18:57 
GeneralRe: My vote of 2 Pin
Raffael Foidl17-Aug-12 23:49
memberRaffael Foidl17-Aug-12 23:49 
GeneralRe: My vote of 2 Pin
Klaus Luedenscheidt18-Aug-12 19:01
memberKlaus Luedenscheidt18-Aug-12 19:01 
GeneralMy vote of 2 Pin
emartinho17-Aug-12 11:57
memberemartinho17-Aug-12 11:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170217.1 | Last Updated 17 Aug 2012
Article Copyright 2012 by Patil Kishor
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid