background image

Language Fundamentals in VB.NET

<< 5. Language Features of VB.NET | Primitive Data types >>
<< 5. Language Features of VB.NET | Primitive Data types >>

As already stated earlier both VB.NET and C# are equally powerful. So the primary
reason for which VB could not reach the zenith of popularity has been eradicated and
programmers who have been waiting for OOPs concepts to be incorporated into VB are
rewarded with this offering of Microsoft.


5.2 Language Fundamentals in VB.NET
Constants &Variables
A variable is a named memory location. They are programming elements that can change
during program execution. Data that needs to be stored in memory & accessed at a later
time are stored in variables. Instead of referring to the memory location by the actual
memory address you refer to it with a variable name.

Variables are declared as follows
Dim a as Integer

They can also be initialized at the time of declaration as follows:
Dim a as Integer = 10

Constants are very similar to variables. The main difference is that the value contained in
memory cannot be changed once the constant is declared. When you declare a constant
its value is also specified and this value cannot be changed during program execution.

Constants are used in situations where we need to keep the value in some memory
location constant. If you use hard-coded values, and the value is changed then it has to be
changed in all the locations in the code where it has been used. Instead if we are using
constants, all we will need to do is to change the value of the constant. This would
propagate the changes to our entire application.

Constants are declared as follows
Const x as Integer