SlideShare uma empresa Scribd logo
1 de 32
Visual Programming with
Visual Basic .NET
Procedures, Functions and Structures
Procedures
 Procedure
 A block of statements enclosed by a declaration
statement and an End statement
 Invoked from some other place in the code
 When finished the execution, returns control to
the code that invoked it

 Provide a way to break larger complex programs
into smaller and simple logical units – Divide and
conquer
 Make code easier to read, understand and debug
 Enable code reusability
 Can be a sub procedure, function procedure or an
event procedure
2
Example
Boss
Worker1

Worker4

Worker2

Worker5

Worker3

Click Here for
more details

 Boss assigns work to the workers
 A worker may assign part of his work to a
subordinate
 Once the given job is completed, boss can continue
with his work
 How the worker does the work is not important here
3
Sub Procedures
 Sub procedure
 A series of statements enclosed by the Sub and
End Sub statements
 Performs actions but does not return a value to the
calling code
 Can take arguments that are passed by the calling
code
 Can define in modules, classes and structures

4
Declaration of Sub Procedures
 Declaration syntax
[AccessSpecifier] Sub Identifier([ParameterList])
[Statements]
End Sub

 AccessSpecifier could be Public, Protected, Friend,
or Private
 If omitted, it is Public by default

 Identifier specifies the identifier of the procedure
 ParameterList is a comma-separated list of
parameters
 Exit Sub statement can be used to exit immediately
from a Sub procedure

5
Declaration of Sub Procedures
 Declaration syntax for Parameters

[ByVal|

ByRef] Identifier As DataType

or

Optional
[ByVal|ByRef] Identifier As DataType = _
DefaultValue

 ByVal or ByRef specifies the argument passing
mechanism
 If omitted, it is assumed ByVal by default

 Optional indicates whether the argument is optional
 If so, a default value must be declared for use in
case, if the calling code does not supply an argument
 Parameters following a parameter corresponding to
an optional argument must also be optional

6
Argument Passing Mechanisms
 Argument can be passed to a procedure by value
or by reference by specifying ByVal or ByRef
keywords, respectively
 Passing by value means the procedure can not
modify the contents of arguments in calling code
 Passing by reference allows the procedure to
modify the contents of arguments in calling code
 Non-variable arguments in calling code are never
modified, even if they are passed by reference

7
Argument Passing Mechanisms
 Passing arguments ByVal
 Protects arguments from being changed by the
procedure
 Affects to the performance due to the copying of
the entire data content of arguments to their
corresponding parameters

 Passing arguments ByRef
 Enables the procedure to return values to the
calling code through the arguments
 Reduces the overhead of copying the arguments to
their corresponding parameters but can lead to an
accidental corruption of caller’s data

8
Function Procedures
 Function procedure
 A series of statements enclosed by the Function
and End Function statements
 Similar to a Sub procedure, but can return a value
to the calling program
 Can take arguments that are passed by the calling
code
 Can define in modules, classes and structures

9
Declaration of Function Procedures
 Declaration syntax
[AccessSpecifier] Function _
Identifier([ParameterList]) [As DataType]
[Statements]
Return ReturnExpression
End Function

 AccessSpecifier could be Public, Protected, Friend,
or Private
 If omitted, it is Public by default

 Identifier specifies the identifier of the function
 ParameterList is a comma-separated list of
parameters
 DataType is the data type of ReturnExpression

10
Structures
 Allows to create User Defined Data Types.
 Once declared, a structure becomes a composite
data type and can declare variables of that
composite type
 Like classes, can have data members and member
functions
 Unlike classes
 Structures are value type, not reference type
 Can not inherit from another structure. So suitable
for objects which are more unlikely to extend
 All members are Public by default

11
Declaration of Structures
 Declaration syntax
[AccessSpecifier] Structure Identifier
MemberVariableDeclarations
[MemberFunctionDeclarations]
End Structure

 Can only be declared at module or class level
 AccessSpecifier could be Public, Protected, Friend, or
Private
 If omitted, it is Friend by default

 Members could be Dim, Public, Friend, or Private, but
not Protected
 Must contain at least one member variable
 Member variables can’t be initialized at the declaration
 Array members should be declared without the size.
Have to use ReDim to resize.
12
Variables of Composite Data Types
 Variables of composite data types can be declared
with the data types defined as the structures
 Declaration syntax
Dim Identifier As CompositeDataType






Can be used at method, class and module levels
Identifier specifies the identifier of the variable
CompositeDataType stands for structure defined
Possible to declare several variables of same type
or of different types in one statement

13
Using Composite Variables
 Members of a composite variable can be accessed
with the period character
 Syntax
CompositeVariable.Member

 To set a value to a member variable
CompositeVariable.MemberVariable = Expression

 To get the value in member variable
CompositeVariable.MemberVariable

 To call a member function
CompositeVariable.MemberFunction([ArgumentList])

14
Methods of Math Class
 Function procedures (Methods) contained in class
“Math”
 Performs mathematical operations and returns a
value

Method

Description

Example

Abs(x)

Returns the absolute value of x

Abs(-23.5) is 23.5

Ceiling(x)

Ceiling(9.2) is 10.0

Cos(x)

Rounds x to the smallest integer
not less than x
Returns trigonometric cosine of x

Exp(x)

Returns the exponential e

x

Cos(0.0) is 1.0
Exp(1.0) is
2.728281828459
05 approximately
15
Methods of Math Class
Method

Description

Example

Max(x,y)

Rounds x to the largest integer not
greater than x
Returns the natural logarithm of x
(base e)
Returns the maximum value of x & y

Min(x,y)

Returns the minimum value of x & y

Pow(x,y)

Calculates x raised to power y

Sin(x)

Returns the trigonometric sine of x

Pow(2.0,7.0) is
128
Sin(0.0) is 0.0

Sqrt(x)

Returns the square root of x

Sqrt(9.0) is 3.0

Tan(x)

Returns the trigonometric tangent
of x

Tan(0.0) is 0.0

Round(x)
Round(X, dp)

Rounds x. If given the # of decimal
places, it rounds to that decimal places

Round(2.3) is 2

Floor(x)
Log(x)

Floor(9.2) is 9.0
Log(2.718281828459
05) is 1.0 app.

Max (5,8) is 8
Min(5,8) is 5

16
Random Number Generation
 What is a random number?
Dim RandomObject as Random = new Random()
Dim RandNum as Integer = RandomObject.Next()

 This generates a positive Integer from 0 to
Int32.Maxvalue i.e. 2,147,483,647
 We can give the range to produce random
numbers.
Value = randomobject.Next(1,7)

 This returns a value between 1-6
 If passed only one parameter, it will return a
value from 0 to the passed value but excluding
that value.
 Rnd() returns a random number between 0 and 1
17
Methods of String Class
 Two types

 Shared Methods –

No Need to mention the instance name

If Compare(strA,strB)

 Non shared Methods -

>

0 Then

…

Needs to mention the instance name

If myString.EndsWith(“ed”) Then
Method

…

Description

EndsWith(x)

Checks whether the string instance ends with x

Equals(x)

Checks whether the string instance equals x

Indexof(X)

Returns the index where strinx x is found in the given string

Insert(startindex, X)

X will be inserted into the given string starting at the given position

Remove(stIndx, NofChrs)

Removes the given # of characters starting at the given position

Replace(oldstr, newstr)

Replace the old string part with the new one

StartsWith(x)

Checks whether the string instance starts with x

ToLower(), ToUpper()

Converts to Lower Case or Upper Case

Trim(), TrimEnd(),
TrimStart()

Remove spaces from both sides, from start or from end
18
Functions to Determine Data Type

Method

Description

IsArray(Variable Name)

Checks whether the variable is an array

IsDate(Expression)

Checks whether the expression is a valid data or time value

IsNumeric(Expression)

Checks whether the expression evaluates to a numeric value

IsObject(variable Name)

Checks whether the variable is an object

Is Nothing

Checks whether the object is set to nothing
If objMyObject Is Nothing Then …

TypeOf

Checks the type of an object variable
If TypeOf txtName is TextBox Then …

TypeName(Variable
Name)

Returns the data type of a non object type variable

19
Date / Time Functions
 When a Date type variable is declared, CLR uses
the DateTime structure, which has an extensible
list of properties and methods
 Now() and Today() are two shared members
Ex.
datToday = Today()
 Non shared members could be used with the
instance name of the DateTime structure

20
Date / Time Functions
Method

Description

Date

Date Component

Day

Integer day of month (1-31)

DayOfWeek

Integer day of week ( 0 = Sunday)

DayOfYear

Integer day of year ( 1-366)

Hour

Integer hour (0-23)

Minute

Integer minute (0-59)

Second

Integer second (0-59)

Month

Integer month ( 1 = January )

Year

Year component

ToLongDateString

Date formatted as long date

ToLongTimeString

Date formatted as long time

ToShortDateString

Date formatted as short date

ToShortTimeString

Date formatted as short time

21
In Built String Functions
Function
InStr
LCase
Left
Len
LTrim
Mid
StrReverse
Right
RTrim
Str
Trim
UCase

Description
Finds the starting position of a substring
within a string
Converts a string to lower case
Finds or removes a specified number of
characters from the beginning of a string
Gives the length of a string
Removes spaces from the beginning of a
string
Finds or removes characters from a
string
Reverses the strings
Finds or removes a specified number of
characters from the end of a string
Removes spaces from the end of a string
Returns the string equivalent of a
number
Trims spaces from both the beginning
and end of a string
Converts a string to upper case

Example
InStr(“My mother”, “mo”) = 4
LCase(“UPPER Case”) = upper case
Left(“Kelaniya”, 6) = “Kelani”
Len(“Hello”) = 5
LTrim(“ Hello “) = “Hello “
Mid(“microsoft”,3,4) = “cros”
strReverse(“Kelaniya”) = “ayinaleK”
Right(“Kelaniya”, 6) = “laniya”
RTrim(“ Hello “) = “ Hello“
Str(12345) = “12345”
Trim(“ Hello “) = “Hello“
UCase(“lower Case”) = “UPPER CASE”

22
Recursive Procedures
 A procedure calls itself for a repetitive task
 Ex. Calculating the Factorial Value

 Any problem that can be solved recursively could
be solved iteratively
 But recursions more naturally mirrors some
problems, hence easy to understand and debug
23
Classes
 Standard programming unit in OOP
 Encapsulate data members and member functions
into one package
 Enable inheritance and polymorphism
 Act as a template for creating objects

24
Declaration of Classes
 Declaration syntax
[AccessSpecifier] Class Identifier
[Inherits BaseClass]
[MemberVariableDeclarations]
[MemberFunctionDeclarations]
End Class

 AccessSpecifier could be Public, Protected, Friend,
or Private
 If omitted, it is Friend by default

 BaseClass specifies class that gives the inheritance
 Members could be Dim, Public, Protected , Friend,
or Private

25
Modules
 Like classes, encapsulate data members and
member functions defined within
 Unlike classes, modules can never be instantiated
and do not support inheritance
 Public members declared in a module are
accessible from anywhere in the project without
using their fully qualified names or an Imports
statement
 Known as global members

 Global variables and constants declared in a
module exist throughout the life of the program

26
Declaration of Modules
 Declaration syntax
[AccessSpecifier] Module Identifier
[MemberVariableDeclarations]
[MemberFunctionDeclarations]
End Module

 AccessSpecifier could only be Public or Friend
 If omitted, it is Friend by default

 Members could be Dim, Public, Protected , Friend,
or Private

27
Scope
 Scope of a declared element is the region in which
it is available and can be referred without using
its fully qualified name or an Imports statement
 Element could be a variable, constant, procedure,
class, structure or an enumeration
 Use care when declaring elements with the same
identifier but with a different scope, because
doing so can lead to unexpected results
 If possible, narrowing the scope of elements when
declaring them is a good programming practice

28
Block Level Scope
 A block is a set of statements terminated by an
End, Else, Loop, or Next statement
 An element declared within a block is accessible
only within that block
 Element could be a variable or a constant
 Even though scope of a block element is limited to
the block, it will exists throughout the procedure
that the block declared

29
Procedure Level Scope
 Also referred to as method level scope
 An element declared within a procedure is
accessible and available only within that
procedure
 Element could be a variable or a constant
 Known as local elements

 All local variables should only be declared using
Dim as the access specifier and are Private by
default

30
Module Level Scope
 Applies equally to modules, classes, and structures
 Scope of an element declared within a module is
determined by the access specifier used at the
declaration
 Elements at this level should be declared outside
of any procedure or block in the module
 Element could be a variable, constant, procedure,
class, structure or an enumeration
 Except for structures, variables declared using
Dim as the access specifier are Private by default

31
Accessibility of Elements
 Accessibility of elements declared at module level

 Public elements
Accessible from
anywhere within the same project and from other
projects that reference the project
 Friend elements
Accessible from within the same project, but not
from outside the project
 Protected elements
Accessible only from within the same class, or from a
class derived from that class
 Private elements
Accessible only from within the same module, class, or
structure

32

Mais conteúdo relacionado

Mais procurados

Asp.NET Validation controls
Asp.NET Validation controlsAsp.NET Validation controls
Asp.NET Validation controlsGuddu gupta
 
Visual basic 6.0
Visual basic 6.0Visual basic 6.0
Visual basic 6.0Aarti P
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVAAbhilash Nair
 
VB Function and procedure
VB Function and procedureVB Function and procedure
VB Function and procedurepragya ratan
 
vb.net Constructor and destructor
vb.net Constructor and destructorvb.net Constructor and destructor
vb.net Constructor and destructorsuraj pandey
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteTushar B Kute
 
C# lecture 2: Literals , Variables and Data Types in C#
C# lecture 2: Literals , Variables and Data Types in C#C# lecture 2: Literals , Variables and Data Types in C#
C# lecture 2: Literals , Variables and Data Types in C#Dr.Neeraj Kumar Pandey
 
Creating a data report in visual basic 6
Creating a data report in visual basic 6Creating a data report in visual basic 6
Creating a data report in visual basic 6mrgulshansharma
 
CONTROL STRUCTURE IN VB
CONTROL STRUCTURE IN VBCONTROL STRUCTURE IN VB
CONTROL STRUCTURE IN VBclassall
 
Menu bars and menus
Menu bars and menusMenu bars and menus
Menu bars and menusmyrajendra
 
Applet life cycle
Applet life cycleApplet life cycle
Applet life cyclemyrajendra
 
Visual programming lecture
Visual programming lecture Visual programming lecture
Visual programming lecture AqsaHayat3
 
Visual Programming
Visual ProgrammingVisual Programming
Visual ProgrammingBagzzz
 

Mais procurados (20)

Data types
Data typesData types
Data types
 
Vectors in Java
Vectors in JavaVectors in Java
Vectors in Java
 
Asp.NET Validation controls
Asp.NET Validation controlsAsp.NET Validation controls
Asp.NET Validation controls
 
Visual basic 6.0
Visual basic 6.0Visual basic 6.0
Visual basic 6.0
 
Understanding Subroutines and Functions in VB6
Understanding Subroutines and Functions in VB6Understanding Subroutines and Functions in VB6
Understanding Subroutines and Functions in VB6
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
VB Function and procedure
VB Function and procedureVB Function and procedure
VB Function and procedure
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
vb.net Constructor and destructor
vb.net Constructor and destructorvb.net Constructor and destructor
vb.net Constructor and destructor
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
 
C# lecture 2: Literals , Variables and Data Types in C#
C# lecture 2: Literals , Variables and Data Types in C#C# lecture 2: Literals , Variables and Data Types in C#
C# lecture 2: Literals , Variables and Data Types in C#
 
VB.net
VB.netVB.net
VB.net
 
Creating a data report in visual basic 6
Creating a data report in visual basic 6Creating a data report in visual basic 6
Creating a data report in visual basic 6
 
Visual Basic Controls ppt
Visual Basic Controls pptVisual Basic Controls ppt
Visual Basic Controls ppt
 
Packages in java
Packages in javaPackages in java
Packages in java
 
CONTROL STRUCTURE IN VB
CONTROL STRUCTURE IN VBCONTROL STRUCTURE IN VB
CONTROL STRUCTURE IN VB
 
Menu bars and menus
Menu bars and menusMenu bars and menus
Menu bars and menus
 
Applet life cycle
Applet life cycleApplet life cycle
Applet life cycle
 
Visual programming lecture
Visual programming lecture Visual programming lecture
Visual programming lecture
 
Visual Programming
Visual ProgrammingVisual Programming
Visual Programming
 

Destaque

Objects and classes in Visual Basic
Objects and classes in Visual BasicObjects and classes in Visual Basic
Objects and classes in Visual BasicSangeetha Sg
 
Presentation on visual basic 6 (vb6)
Presentation on visual basic 6 (vb6)Presentation on visual basic 6 (vb6)
Presentation on visual basic 6 (vb6)pbarasia
 
Basic controls of Visual Basic 6.0
Basic controls of Visual Basic 6.0Basic controls of Visual Basic 6.0
Basic controls of Visual Basic 6.0Salim M
 
Visual basic ppt for tutorials computer
Visual basic ppt for tutorials computerVisual basic ppt for tutorials computer
Visual basic ppt for tutorials computersimran153
 
Introduction to visual basic programming
Introduction to visual basic programmingIntroduction to visual basic programming
Introduction to visual basic programmingRoger Argarin
 
Introduction to VB
Introduction to VBIntroduction to VB
Introduction to VBMukesh Das
 
Pass by value and pass by reference
Pass by value and pass by reference Pass by value and pass by reference
Pass by value and pass by reference TurnToTech
 
Part 12 built in function vb.net
Part 12 built in function vb.netPart 12 built in function vb.net
Part 12 built in function vb.netGirija Muscut
 
Menu pop up menu mdi form and playing audio in vb
Menu pop up menu mdi form and playing audio in vbMenu pop up menu mdi form and playing audio in vb
Menu pop up menu mdi form and playing audio in vbAmandeep Kaur
 
Vb net xp_04
Vb net xp_04Vb net xp_04
Vb net xp_04Niit Care
 
Vb net xp_11
Vb net xp_11Vb net xp_11
Vb net xp_11Niit Care
 
Date & time functions in VB.NET
Date & time functions in VB.NETDate & time functions in VB.NET
Date & time functions in VB.NETA R
 
Mdi Presentation
Mdi PresentationMdi Presentation
Mdi PresentationKieran Lamb
 

Destaque (20)

Objects and classes in Visual Basic
Objects and classes in Visual BasicObjects and classes in Visual Basic
Objects and classes in Visual Basic
 
Presentation on visual basic 6 (vb6)
Presentation on visual basic 6 (vb6)Presentation on visual basic 6 (vb6)
Presentation on visual basic 6 (vb6)
 
Basic controls of Visual Basic 6.0
Basic controls of Visual Basic 6.0Basic controls of Visual Basic 6.0
Basic controls of Visual Basic 6.0
 
Visual basic ppt for tutorials computer
Visual basic ppt for tutorials computerVisual basic ppt for tutorials computer
Visual basic ppt for tutorials computer
 
INPUT BOX- VBA
INPUT BOX- VBAINPUT BOX- VBA
INPUT BOX- VBA
 
Introduction to visual basic programming
Introduction to visual basic programmingIntroduction to visual basic programming
Introduction to visual basic programming
 
Introduction to VB
Introduction to VBIntroduction to VB
Introduction to VB
 
Pass by value and pass by reference
Pass by value and pass by reference Pass by value and pass by reference
Pass by value and pass by reference
 
Notas InputBox
Notas InputBoxNotas InputBox
Notas InputBox
 
InputBox
InputBoxInputBox
InputBox
 
Part 12 built in function vb.net
Part 12 built in function vb.netPart 12 built in function vb.net
Part 12 built in function vb.net
 
Date function
Date functionDate function
Date function
 
Menu pop up menu mdi form and playing audio in vb
Menu pop up menu mdi form and playing audio in vbMenu pop up menu mdi form and playing audio in vb
Menu pop up menu mdi form and playing audio in vb
 
Vb net xp_04
Vb net xp_04Vb net xp_04
Vb net xp_04
 
Vb
VbVb
Vb
 
Active x
Active xActive x
Active x
 
Vb net xp_11
Vb net xp_11Vb net xp_11
Vb net xp_11
 
Date & time functions in VB.NET
Date & time functions in VB.NETDate & time functions in VB.NET
Date & time functions in VB.NET
 
User Defined Functions
User Defined FunctionsUser Defined Functions
User Defined Functions
 
Mdi Presentation
Mdi PresentationMdi Presentation
Mdi Presentation
 

Semelhante a Procedures functions structures in VB.Net

Variable and constants in Vb.NET
Variable and constants in Vb.NETVariable and constants in Vb.NET
Variable and constants in Vb.NETJaya Kumari
 
Visula C# Programming Lecture 6
Visula C# Programming Lecture 6Visula C# Programming Lecture 6
Visula C# Programming Lecture 6Abou Bakr Ashraf
 
Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]Palak Sanghani
 
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...vekariyakashyap
 
Breaking down data silos with the open data protocol
Breaking down data silos with the open data protocolBreaking down data silos with the open data protocol
Breaking down data silos with the open data protocolWoodruff Solutions LLC
 
procedures and arrays
procedures and arraysprocedures and arrays
procedures and arraysDivyaR219113
 
TDD And Refactoring
TDD And RefactoringTDD And Refactoring
TDD And RefactoringNaresh Jain
 
Chapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part IIChapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part IIEduardo Bergavera
 
Java căn bản - Chapter7
Java căn bản - Chapter7Java căn bản - Chapter7
Java căn bản - Chapter7Vince Vo
 
Advanced c#
Advanced c#Advanced c#
Advanced c#saranuru
 
PPT ON VHDL subprogram,package,alias,use,generate and concurrent statments an...
PPT ON VHDL subprogram,package,alias,use,generate and concurrent statments an...PPT ON VHDL subprogram,package,alias,use,generate and concurrent statments an...
PPT ON VHDL subprogram,package,alias,use,generate and concurrent statments an...Khushboo Jain
 
Chapter2pp
Chapter2ppChapter2pp
Chapter2ppJ. C.
 
Chapter 3.4
Chapter 3.4Chapter 3.4
Chapter 3.4sotlsoc
 

Semelhante a Procedures functions structures in VB.Net (20)

Variable and constants in Vb.NET
Variable and constants in Vb.NETVariable and constants in Vb.NET
Variable and constants in Vb.NET
 
Visula C# Programming Lecture 6
Visula C# Programming Lecture 6Visula C# Programming Lecture 6
Visula C# Programming Lecture 6
 
Java q ref 2018
Java q ref 2018Java q ref 2018
Java q ref 2018
 
Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]
 
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
 
CIS160 final review
CIS160 final reviewCIS160 final review
CIS160 final review
 
Breaking down data silos with the open data protocol
Breaking down data silos with the open data protocolBreaking down data silos with the open data protocol
Breaking down data silos with the open data protocol
 
procedures and arrays
procedures and arraysprocedures and arrays
procedures and arrays
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
VHDL lecture 2.ppt
VHDL lecture 2.pptVHDL lecture 2.ppt
VHDL lecture 2.ppt
 
Stored procedures
Stored proceduresStored procedures
Stored procedures
 
vb.net.pdf
vb.net.pdfvb.net.pdf
vb.net.pdf
 
TDD And Refactoring
TDD And RefactoringTDD And Refactoring
TDD And Refactoring
 
Chapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part IIChapter 7 - Defining Your Own Classes - Part II
Chapter 7 - Defining Your Own Classes - Part II
 
Java căn bản - Chapter7
Java căn bản - Chapter7Java căn bản - Chapter7
Java căn bản - Chapter7
 
Of Lambdas and LINQ
Of Lambdas and LINQOf Lambdas and LINQ
Of Lambdas and LINQ
 
Advanced c#
Advanced c#Advanced c#
Advanced c#
 
PPT ON VHDL subprogram,package,alias,use,generate and concurrent statments an...
PPT ON VHDL subprogram,package,alias,use,generate and concurrent statments an...PPT ON VHDL subprogram,package,alias,use,generate and concurrent statments an...
PPT ON VHDL subprogram,package,alias,use,generate and concurrent statments an...
 
Chapter2pp
Chapter2ppChapter2pp
Chapter2pp
 
Chapter 3.4
Chapter 3.4Chapter 3.4
Chapter 3.4
 

Mais de tjunicornfx

C++ Question & Answer
C++ Question & AnswerC++ Question & Answer
C++ Question & Answertjunicornfx
 
Mechanical element of a CNC Machine
Mechanical element of a CNC MachineMechanical element of a CNC Machine
Mechanical element of a CNC Machinetjunicornfx
 
AC in Vehicle -Sinhala note (Sri lanka) 1
AC in Vehicle -Sinhala note (Sri lanka) 1AC in Vehicle -Sinhala note (Sri lanka) 1
AC in Vehicle -Sinhala note (Sri lanka) 1tjunicornfx
 
AC in Vehicle -Sinhala note (Sri lanka) -3
AC in Vehicle -Sinhala note (Sri lanka) -3AC in Vehicle -Sinhala note (Sri lanka) -3
AC in Vehicle -Sinhala note (Sri lanka) -3tjunicornfx
 
AC in Vehicle -Sinhala note (Sri lanka) -2
AC in Vehicle -Sinhala note (Sri lanka) -2AC in Vehicle -Sinhala note (Sri lanka) -2
AC in Vehicle -Sinhala note (Sri lanka) -2tjunicornfx
 
Computer architecture for HNDIT
Computer architecture for HNDITComputer architecture for HNDIT
Computer architecture for HNDITtjunicornfx
 
Artificail Intelligent lec-1
Artificail Intelligent lec-1Artificail Intelligent lec-1
Artificail Intelligent lec-1tjunicornfx
 
Security architecture
Security architectureSecurity architecture
Security architecturetjunicornfx
 
04 introduction to computer networking
04 introduction to computer networking04 introduction to computer networking
04 introduction to computer networkingtjunicornfx
 

Mais de tjunicornfx (10)

C++ Question & Answer
C++ Question & AnswerC++ Question & Answer
C++ Question & Answer
 
ASP
ASPASP
ASP
 
Mechanical element of a CNC Machine
Mechanical element of a CNC MachineMechanical element of a CNC Machine
Mechanical element of a CNC Machine
 
AC in Vehicle -Sinhala note (Sri lanka) 1
AC in Vehicle -Sinhala note (Sri lanka) 1AC in Vehicle -Sinhala note (Sri lanka) 1
AC in Vehicle -Sinhala note (Sri lanka) 1
 
AC in Vehicle -Sinhala note (Sri lanka) -3
AC in Vehicle -Sinhala note (Sri lanka) -3AC in Vehicle -Sinhala note (Sri lanka) -3
AC in Vehicle -Sinhala note (Sri lanka) -3
 
AC in Vehicle -Sinhala note (Sri lanka) -2
AC in Vehicle -Sinhala note (Sri lanka) -2AC in Vehicle -Sinhala note (Sri lanka) -2
AC in Vehicle -Sinhala note (Sri lanka) -2
 
Computer architecture for HNDIT
Computer architecture for HNDITComputer architecture for HNDIT
Computer architecture for HNDIT
 
Artificail Intelligent lec-1
Artificail Intelligent lec-1Artificail Intelligent lec-1
Artificail Intelligent lec-1
 
Security architecture
Security architectureSecurity architecture
Security architecture
 
04 introduction to computer networking
04 introduction to computer networking04 introduction to computer networking
04 introduction to computer networking
 

Último

Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 

Último (20)

Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 

Procedures functions structures in VB.Net

  • 1. Visual Programming with Visual Basic .NET Procedures, Functions and Structures
  • 2. Procedures  Procedure  A block of statements enclosed by a declaration statement and an End statement  Invoked from some other place in the code  When finished the execution, returns control to the code that invoked it  Provide a way to break larger complex programs into smaller and simple logical units – Divide and conquer  Make code easier to read, understand and debug  Enable code reusability  Can be a sub procedure, function procedure or an event procedure 2
  • 3. Example Boss Worker1 Worker4 Worker2 Worker5 Worker3 Click Here for more details  Boss assigns work to the workers  A worker may assign part of his work to a subordinate  Once the given job is completed, boss can continue with his work  How the worker does the work is not important here 3
  • 4. Sub Procedures  Sub procedure  A series of statements enclosed by the Sub and End Sub statements  Performs actions but does not return a value to the calling code  Can take arguments that are passed by the calling code  Can define in modules, classes and structures 4
  • 5. Declaration of Sub Procedures  Declaration syntax [AccessSpecifier] Sub Identifier([ParameterList]) [Statements] End Sub  AccessSpecifier could be Public, Protected, Friend, or Private  If omitted, it is Public by default  Identifier specifies the identifier of the procedure  ParameterList is a comma-separated list of parameters  Exit Sub statement can be used to exit immediately from a Sub procedure 5
  • 6. Declaration of Sub Procedures  Declaration syntax for Parameters [ByVal| ByRef] Identifier As DataType or Optional [ByVal|ByRef] Identifier As DataType = _ DefaultValue  ByVal or ByRef specifies the argument passing mechanism  If omitted, it is assumed ByVal by default  Optional indicates whether the argument is optional  If so, a default value must be declared for use in case, if the calling code does not supply an argument  Parameters following a parameter corresponding to an optional argument must also be optional 6
  • 7. Argument Passing Mechanisms  Argument can be passed to a procedure by value or by reference by specifying ByVal or ByRef keywords, respectively  Passing by value means the procedure can not modify the contents of arguments in calling code  Passing by reference allows the procedure to modify the contents of arguments in calling code  Non-variable arguments in calling code are never modified, even if they are passed by reference 7
  • 8. Argument Passing Mechanisms  Passing arguments ByVal  Protects arguments from being changed by the procedure  Affects to the performance due to the copying of the entire data content of arguments to their corresponding parameters  Passing arguments ByRef  Enables the procedure to return values to the calling code through the arguments  Reduces the overhead of copying the arguments to their corresponding parameters but can lead to an accidental corruption of caller’s data 8
  • 9. Function Procedures  Function procedure  A series of statements enclosed by the Function and End Function statements  Similar to a Sub procedure, but can return a value to the calling program  Can take arguments that are passed by the calling code  Can define in modules, classes and structures 9
  • 10. Declaration of Function Procedures  Declaration syntax [AccessSpecifier] Function _ Identifier([ParameterList]) [As DataType] [Statements] Return ReturnExpression End Function  AccessSpecifier could be Public, Protected, Friend, or Private  If omitted, it is Public by default  Identifier specifies the identifier of the function  ParameterList is a comma-separated list of parameters  DataType is the data type of ReturnExpression 10
  • 11. Structures  Allows to create User Defined Data Types.  Once declared, a structure becomes a composite data type and can declare variables of that composite type  Like classes, can have data members and member functions  Unlike classes  Structures are value type, not reference type  Can not inherit from another structure. So suitable for objects which are more unlikely to extend  All members are Public by default 11
  • 12. Declaration of Structures  Declaration syntax [AccessSpecifier] Structure Identifier MemberVariableDeclarations [MemberFunctionDeclarations] End Structure  Can only be declared at module or class level  AccessSpecifier could be Public, Protected, Friend, or Private  If omitted, it is Friend by default  Members could be Dim, Public, Friend, or Private, but not Protected  Must contain at least one member variable  Member variables can’t be initialized at the declaration  Array members should be declared without the size. Have to use ReDim to resize. 12
  • 13. Variables of Composite Data Types  Variables of composite data types can be declared with the data types defined as the structures  Declaration syntax Dim Identifier As CompositeDataType     Can be used at method, class and module levels Identifier specifies the identifier of the variable CompositeDataType stands for structure defined Possible to declare several variables of same type or of different types in one statement 13
  • 14. Using Composite Variables  Members of a composite variable can be accessed with the period character  Syntax CompositeVariable.Member  To set a value to a member variable CompositeVariable.MemberVariable = Expression  To get the value in member variable CompositeVariable.MemberVariable  To call a member function CompositeVariable.MemberFunction([ArgumentList]) 14
  • 15. Methods of Math Class  Function procedures (Methods) contained in class “Math”  Performs mathematical operations and returns a value Method Description Example Abs(x) Returns the absolute value of x Abs(-23.5) is 23.5 Ceiling(x) Ceiling(9.2) is 10.0 Cos(x) Rounds x to the smallest integer not less than x Returns trigonometric cosine of x Exp(x) Returns the exponential e x Cos(0.0) is 1.0 Exp(1.0) is 2.728281828459 05 approximately 15
  • 16. Methods of Math Class Method Description Example Max(x,y) Rounds x to the largest integer not greater than x Returns the natural logarithm of x (base e) Returns the maximum value of x & y Min(x,y) Returns the minimum value of x & y Pow(x,y) Calculates x raised to power y Sin(x) Returns the trigonometric sine of x Pow(2.0,7.0) is 128 Sin(0.0) is 0.0 Sqrt(x) Returns the square root of x Sqrt(9.0) is 3.0 Tan(x) Returns the trigonometric tangent of x Tan(0.0) is 0.0 Round(x) Round(X, dp) Rounds x. If given the # of decimal places, it rounds to that decimal places Round(2.3) is 2 Floor(x) Log(x) Floor(9.2) is 9.0 Log(2.718281828459 05) is 1.0 app. Max (5,8) is 8 Min(5,8) is 5 16
  • 17. Random Number Generation  What is a random number? Dim RandomObject as Random = new Random() Dim RandNum as Integer = RandomObject.Next()  This generates a positive Integer from 0 to Int32.Maxvalue i.e. 2,147,483,647  We can give the range to produce random numbers. Value = randomobject.Next(1,7)  This returns a value between 1-6  If passed only one parameter, it will return a value from 0 to the passed value but excluding that value.  Rnd() returns a random number between 0 and 1 17
  • 18. Methods of String Class  Two types  Shared Methods – No Need to mention the instance name If Compare(strA,strB)  Non shared Methods - > 0 Then … Needs to mention the instance name If myString.EndsWith(“ed”) Then Method … Description EndsWith(x) Checks whether the string instance ends with x Equals(x) Checks whether the string instance equals x Indexof(X) Returns the index where strinx x is found in the given string Insert(startindex, X) X will be inserted into the given string starting at the given position Remove(stIndx, NofChrs) Removes the given # of characters starting at the given position Replace(oldstr, newstr) Replace the old string part with the new one StartsWith(x) Checks whether the string instance starts with x ToLower(), ToUpper() Converts to Lower Case or Upper Case Trim(), TrimEnd(), TrimStart() Remove spaces from both sides, from start or from end 18
  • 19. Functions to Determine Data Type Method Description IsArray(Variable Name) Checks whether the variable is an array IsDate(Expression) Checks whether the expression is a valid data or time value IsNumeric(Expression) Checks whether the expression evaluates to a numeric value IsObject(variable Name) Checks whether the variable is an object Is Nothing Checks whether the object is set to nothing If objMyObject Is Nothing Then … TypeOf Checks the type of an object variable If TypeOf txtName is TextBox Then … TypeName(Variable Name) Returns the data type of a non object type variable 19
  • 20. Date / Time Functions  When a Date type variable is declared, CLR uses the DateTime structure, which has an extensible list of properties and methods  Now() and Today() are two shared members Ex. datToday = Today()  Non shared members could be used with the instance name of the DateTime structure 20
  • 21. Date / Time Functions Method Description Date Date Component Day Integer day of month (1-31) DayOfWeek Integer day of week ( 0 = Sunday) DayOfYear Integer day of year ( 1-366) Hour Integer hour (0-23) Minute Integer minute (0-59) Second Integer second (0-59) Month Integer month ( 1 = January ) Year Year component ToLongDateString Date formatted as long date ToLongTimeString Date formatted as long time ToShortDateString Date formatted as short date ToShortTimeString Date formatted as short time 21
  • 22. In Built String Functions Function InStr LCase Left Len LTrim Mid StrReverse Right RTrim Str Trim UCase Description Finds the starting position of a substring within a string Converts a string to lower case Finds or removes a specified number of characters from the beginning of a string Gives the length of a string Removes spaces from the beginning of a string Finds or removes characters from a string Reverses the strings Finds or removes a specified number of characters from the end of a string Removes spaces from the end of a string Returns the string equivalent of a number Trims spaces from both the beginning and end of a string Converts a string to upper case Example InStr(“My mother”, “mo”) = 4 LCase(“UPPER Case”) = upper case Left(“Kelaniya”, 6) = “Kelani” Len(“Hello”) = 5 LTrim(“ Hello “) = “Hello “ Mid(“microsoft”,3,4) = “cros” strReverse(“Kelaniya”) = “ayinaleK” Right(“Kelaniya”, 6) = “laniya” RTrim(“ Hello “) = “ Hello“ Str(12345) = “12345” Trim(“ Hello “) = “Hello“ UCase(“lower Case”) = “UPPER CASE” 22
  • 23. Recursive Procedures  A procedure calls itself for a repetitive task  Ex. Calculating the Factorial Value  Any problem that can be solved recursively could be solved iteratively  But recursions more naturally mirrors some problems, hence easy to understand and debug 23
  • 24. Classes  Standard programming unit in OOP  Encapsulate data members and member functions into one package  Enable inheritance and polymorphism  Act as a template for creating objects 24
  • 25. Declaration of Classes  Declaration syntax [AccessSpecifier] Class Identifier [Inherits BaseClass] [MemberVariableDeclarations] [MemberFunctionDeclarations] End Class  AccessSpecifier could be Public, Protected, Friend, or Private  If omitted, it is Friend by default  BaseClass specifies class that gives the inheritance  Members could be Dim, Public, Protected , Friend, or Private 25
  • 26. Modules  Like classes, encapsulate data members and member functions defined within  Unlike classes, modules can never be instantiated and do not support inheritance  Public members declared in a module are accessible from anywhere in the project without using their fully qualified names or an Imports statement  Known as global members  Global variables and constants declared in a module exist throughout the life of the program 26
  • 27. Declaration of Modules  Declaration syntax [AccessSpecifier] Module Identifier [MemberVariableDeclarations] [MemberFunctionDeclarations] End Module  AccessSpecifier could only be Public or Friend  If omitted, it is Friend by default  Members could be Dim, Public, Protected , Friend, or Private 27
  • 28. Scope  Scope of a declared element is the region in which it is available and can be referred without using its fully qualified name or an Imports statement  Element could be a variable, constant, procedure, class, structure or an enumeration  Use care when declaring elements with the same identifier but with a different scope, because doing so can lead to unexpected results  If possible, narrowing the scope of elements when declaring them is a good programming practice 28
  • 29. Block Level Scope  A block is a set of statements terminated by an End, Else, Loop, or Next statement  An element declared within a block is accessible only within that block  Element could be a variable or a constant  Even though scope of a block element is limited to the block, it will exists throughout the procedure that the block declared 29
  • 30. Procedure Level Scope  Also referred to as method level scope  An element declared within a procedure is accessible and available only within that procedure  Element could be a variable or a constant  Known as local elements  All local variables should only be declared using Dim as the access specifier and are Private by default 30
  • 31. Module Level Scope  Applies equally to modules, classes, and structures  Scope of an element declared within a module is determined by the access specifier used at the declaration  Elements at this level should be declared outside of any procedure or block in the module  Element could be a variable, constant, procedure, class, structure or an enumeration  Except for structures, variables declared using Dim as the access specifier are Private by default 31
  • 32. Accessibility of Elements  Accessibility of elements declared at module level  Public elements Accessible from anywhere within the same project and from other projects that reference the project  Friend elements Accessible from within the same project, but not from outside the project  Protected elements Accessible only from within the same class, or from a class derived from that class  Private elements Accessible only from within the same module, class, or structure 32