Beruflich Dokumente
Kultur Dokumente
ANDHRAPRADESH
Name : K. Sreeramacharyulu
Designation : Lecturer
Branch : Commercial and Computer Practice
Institute : Govt. Polytechnic, Srikakulam
Year/Semester : V Semester
Subject : VISUAL BASIC-I
Sub. Code : CCP-503
Topic : Programming Fundamentals
Duration : 50 Minutes
Sub. Topic : Procedures and Functions in VB
Teaching Aids : PPT, Clips and Images
CCP503.36 1
Objectives
CCP503.36 2
RECAP
CCP503.36 3
VB AS AN EVENT-DRIVEN LANGUAGE
Nothing happens in a VB Project until some event occur
Once an Event is detected, the project finds series of
instructions related to event, called an event procedure
That procedure is executed and then program control
returns to the form
Event Procedures are the actual computer programming
instructions that are saved with the form, with extension
‘.frm’
Due to above reasons, VB is called as Event-Driven
Procedural Language
CCP503.36 4
INTRODUCTION TO SUB-PROGRAMS
In any Programming Language such as C / Pascal /
Fortran / C++ / Java etc,. The code used in VB or any
other High Level programming Language will not be a
monolithic listing
No programmer can write a single and big in size of
Project
A big project is usually divided into some set of smaller
units, which are self-contained segments
These smaller units are called Modules.
Sub programs can be repeatedly used from same form
or other forms or even other applications
CCP503.36 5
ADVANTAGES OF SUB PROGRAMS
When you are incorporating the Sub-
Programs in to the VB Program, the
following advantages exists.
Easy to Understand
Easy to Debug
Reusability of code
CCP503.36 6
SUB-PROGRAMS IN VB
CCP503.36 7
SUB PROCEDURES
Definition:
Block of statements that carries out a well-defined task
Block of statements is placed within a pair of sub / End
sub statements and can be invoked by its name
General Syntax:
[Private/Public] [Static] sub <Procedure name> ( [Arguments])
<statements>
End sub
Sub & end sub are called wrapper lines which can be
added with Tools ->Add procedure
CCP503.36 8
Example:
The following subroutine displays the current date
in a Message box and can be called by its name ,
Showdate:
Sub ShowDate()
MsgBox Date()
End sub
CCP503.36 9
CLASSIFICATION OF PROCEDURES
1. General Procedures
3. Event Procedures
CCP503.36 10
1. General Procedures
CCP503.36 11
Syntax:
CCP503.36 12
2. Event Procedure
Blocks of code that are executed when a specific event
occurs , such as the Click of a command button or
Loading/clicking of a form etc.,
Syntax:
Private Sub <ObjectName_EventName> ([Arguments])
<statements>
End sub
CCP503.36 14
CCP503.36 15
CCP503.36 16
Fig 36.1
SUMMARY
About the concepts of Sub-Programming in Computer
High Level Languages.
Types of Sub-Programs, the real advantages of Sub-
Programming.
The concepts of Procedures and functions
CCP503.36 17
FREQUENTLY ASKED QUESTIONS
1. Explain Sub-Programming in any Computer High Level
Languages?
2. List and explain in brief about the types and advantages
of Sub-Programs?
3. What is a Procedure in VB and give a suitable
example?
CCP503.36 18
QUIZ
1 A subprogram that won’t return anything to
the calling program is…
B. Procedure
C. Function
D. Event Procedure
E. Module Program
CCP503.36 19
2. A block of code, that returns a value / result to
calling program is called…
A. Procedure
B. Function
C. Subprogram
D. Main Program
CCP503.36 20
1 The advantage of the Sub-Programming in any
Programming Language is ?
A. Easy to Understand
CCP503.36 21
ASSIGNMENT
1. Write a procedure that shows the day name of
the system date
CCP503.36 22