Procedures & Functions in Visual Basic
Procedures & Functions in Visual Basic
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
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.