Variable: Presented By:-Ms. Rinkle Aswani Lecturer, JIMS
Variable: Presented By:-Ms. Rinkle Aswani Lecturer, JIMS
Presented by:-
Ms. Rinkle Aswani
Lecturer, JIMS
Objectives
• Understand the meaning of variables
• Declare and use variables
• Understand and use various programming
constructs like decision-making and
looping
• Understand the use of modules
• Understand the use of procedures
• Understand the use of functions
VARIABLES
• VB, like most programming languages
uses variables for storing values.
• Variables have a
– name
– data type.
Declaring Variables
• We do not have to explicitly declare or
create variables in VB. If we use a name in
our code that is not the name of any
existing variable, VB creates a new
variable with that name.
• it is good programming practice to
explicitly declare our variables because it
might save debugging time later
Option Explicit
• Adding an Option Explicit statement
to the declaration section of each form,
standard or class module will force us to
declare the variables.
Dim statement
• Dim variable [As type]
• A variable declared with the Dim statement
within a procedure exists only as long as the
procedure is executing. When the procedure
finishes, the value of the variable disappears. In
addition, the value of the variable in the
procedure is local to the procedure. i.e. we
cannot access a variable of one procedure from
another procedure.
Other ways to declare variables:
Text1.text=x
Variable Data Types
• Integer
• Long
• Single
• Double
• Currency
• String
• Byte
• Boolean
• Date
• Object
• Variant
Default
• Default data type in VB is variant
Fundamental VB data types
Type Name Storage size Range
Contd..
Fundamental VB data types
Type Name Storage Range
size
Double 8 Bytes 1.79769313486231E308 to
-4.94065645841247E-324
(Negative-values)
4.94065645841247E-324 to
1.79769313486231E308
(Positive Values)
Contd..
Fundamental VB data types
Type Name Storage Range
size
Byte 1 Byte 0 to 255
Contd..
Fundamental VB data types
Type Name Storage Range
size
Object 4 Bytes Any object reference