0% found this document useful (0 votes)
23 views4 pages

Procedures & Functions in Visual Basic

Procedures and functions are used to create modular Visual Basic programs. Procedures and functions group code into blocks defined by Sub/Function and End statements. The difference is that functions return values while procedures do not. Using procedures and functions improves code clarity, reusability, and modularity by decomposing problems, reducing duplicate code, and hiding implementation details.

Uploaded by

jhenny
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views4 pages

Procedures & Functions in Visual Basic

Procedures and functions are used to create modular Visual Basic programs. Procedures and functions group code into blocks defined by Sub/Function and End statements. The difference is that functions return values while procedures do not. Using procedures and functions improves code clarity, reusability, and modularity by decomposing problems, reducing duplicate code, and hiding implementation details.

Uploaded by

jhenny
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Procedures & functions in Visual Basic

We use procedures and functions to create modular


programs. Visual Basic statements are grouped in a
block enclosed by Sub, Function and
matching End statements. The difference between
the two is that functions return values, procedures
do not.
A procedure and function is a piece of code in a
larger program. They perform a specific task. The
advantages of using procedures and functions are:
Reducing duplication of code
Decomposing complex problems into simpler
pieces
Improving clarity of the code
Reuse of code
Information hiding

Procedures
A procedure is a block of Visual Basic statements
inside Sub, End Sub statements. Procedures do not
return values.
Option Strict On
Module Example
Sub Main()
SimpleProcedure()
End Sub
Sub SimpleProcedure()
Console.WriteLine("Simple
procedure")
End Sub
End Module
This example shows basic usage of procedures. In our
program, we have two procedures. The Main()procedure
and the user defined SimpleProcedure(). As we

already know, the Main() procedure is the entry

point of a Visual Basic

Functions
A function is a block of Visual Basic statements
inside Function, End Function statements. Functions return
values.
There are two basic types of functions. Built-in functions and user
defined ones. The built-in functions are part of the Visual Basic
language. There are various mathematical, string or conversion
functions.
Option Strict On
Module Example
Sub Main()
Console.WriteLine(Math.Abs(-23))
Console.WriteLine(Math.Round(34.56))
Console.WriteLine("ZetCode has {0}
characters", _
Len("ZetCode"))
End Sub
End Module
In the preceding example, we use two math functions and one
string function. Built-in functions help programmers do some
common tasks.

In the following example, we have a user defined function.

You might also like