CCP503
CCP503
ANDHRA PRADESH
Name : K SREE RAMACHARYULU
Designation : LECTURER
Branch : Commercial & Comp. Practice
Institute : Govt. Polytechnic,
SRIKAKULAM
Year / Semester :V
Subject : Visual Basic-I
Subject Code : CCP-503
Duration : 50 Minuets
Topic : Programming Fundamentals
Sub. Topic : VB Environment, Basics of VB
Programming Fundamentals
Teaching Aids : PPT, Animation Clips & Images
CCP503.24 1
Objective :
CCP503.24 2
Structure
Scope of variable
Example
CCP503.24 3
Recap
In the previous session, you have learnt about
Types of Variables
Numeric Variables
Non-numeric Variables
CCP503.24 4
Types of variables supported by VB
CCP503.24 5
Visual Basic Variable Scope
The scope of variable is the section of the application
that can access the variable.
Where a variable can be accessed depends on how it is
declared
Local scope (Dim) – only within Procedure (Sub or
Function) in which it is declared
Module Scope (Private) – available in every Procedure
within a module
Global Scope (Public) – available throughout application
Controlling scope makes it possible to work within
contexts, so that variable names can be reused
with no conflicts
CCP503.24 6
Decides scope of VB Declarations
CCP503.24 7
Visual Basic Module Structure
CCP503.24 8
Lifetime of the variable
Life time is the period for which variable retains its value.
CCP503.24 9
Static variable
CCP503.24 10
VB Local & Static Variables
Local variables (within
Sub or Function)
Declared with Dim are Sub Forgettable( )
reset to zero every time Dim Number As Integer
Procedure is called Number = Number + 1
End Sub Always 1
Declared with Static, at End Sub
retain their value
Sub Persistent()
Dim CallCount As
Integer
CallCount = CallCount +
1
End Sub Counts
up
CCP503.24 11
Visual Basic Variant Type
A Variant is an all purpose variable
Type is always Variant
Sub-Type matches whatever value is assigned
Sub-Type changes to suit
CCP503.24 12
VB User Defined Types
A UDT is composed of simple types
(Integers, strings etc.)
Each instance contains one of each
component variable
Must be placed in Standard Modules
Definition is Global (available
throughout program)
Useful for grouping related information
CCP503.24 13
Visual Basic - An example User Defined
(UDT)
Type Phone Entry
Name As String
Telephone As String
End Type
Dim PE As Phone Entry
PE.Name = “Fred Bloggs”
PE.Telephone = “2468”
Print PE.Name,
PE.Telephone
CCP503.24 14
Constants in VB
CCP503.24 16
Quiz
1. What is a local Variable ?
A) Declared in a Application
B) Declared in a Procedure
C) Declared in the module
D) Declared in the form level
CCP503.24 17
1. What is user defined variable?
CCP503.24 18
Quiz
CCP503.24 19
Frequently asked questions
1. Explain in brief about the scope of variables in
Visual Basic
2. Briefly explain about the lifetime of a variable with
one example?
3. What is user defined variable? Give an example.
CCP503.24 20