Practical No.
15: Write a program to demonstrate use of Sub-procedures and parameterized
Sub-Procedure.
Practical No 15
VIII. Resources required (Additional)
If any web resources required.
X. Resources used (Additional)
https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-
features/procedures/sub-procedures
https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-
features/procedures/procedure-parameters-and-arguments
XI. Program Code
1. Write a program using sub procedure and parameterized sub procedure
Module Module1
Sub Main()
displaymsg()
Dim a, b As Integer
Console.WriteLine("Enter Value")
a = Console.ReadLine()
b = Console.ReadLine()
Add(a, b)
Console.ReadLine()
End Sub
Sub displaymsg()
Console.WriteLine("Use of sub-procedure")
End Sub
Sub Add(ByVal a As Integer, ByVal b As Integer)
Console.WriteLine("Addition = " & a + b)
End Sub
End Module
XII. Results (output of the program)
Use of sub-procedure
Enter Value
10
10
Addition = 20
GUI Application Development using VB.Net (22034) Page 1
Practical No. 15: Write a program to demonstrate use of Sub-procedures and parameterized
Sub-Procedure.
XIII. Practical related Questions
1. Differentiate between ByVal and ByRef keywords in parameter passing of Sub
Procedure.
ByVal and ByRef in VB .NET. When you pass arguments over to Subs and Function you can
do so either By Value or By Reference. By Value is shortened to ByVal and By Reference is
shortened to ByRef. ByVal means that you are passing a copy of a variable to your
Subroutine.
2. Write the program using Recursion. (Factorial of Number)
Module Module1
Sub Main()
Dim num As Integer
Console.WriteLine("Enter a Number")
num = Console.ReadLine()
factorial(num)
Console.ReadLine()
End Sub
Sub factorial(ByVal num As Integer)
' local variable declaration */
Dim i, factorial As Integer
factorial = 1
For i = 1 To num
factorial = factorial * i
Next i
Console.WriteLine("Factorial=" & factorial)
Console.ReadLine()
End Sub
End Module
OUTPUT:
Enter a Number
5
Factorial=120
GUI Application Development using VB.Net (22034) Page 2
Practical No. 15: Write a program to demonstrate use of Sub-procedures and parameterized
Sub-Procedure.
XIV. Exercise
1. Develop a program to calculate the Fibonacci Series of Give Number.
Module Module1
Sub Main()
Fibonacci(10)
Console.ReadLine()
End Sub
Sub Fibonacci(ByVal n As Integer)
Dim a As Integer = 0
Dim b As Integer = 1
Dim i As Integer
For i = 0 To n - 1
Dim temp As Integer
temp = a
a = b
b = temp + b
Console.WriteLine(a)
Next
End Sub
End Module
OUTPUT:
1
1
2
3
5
8
13
21
34
55
2. Develop a program to print the reverse of any number using Sub procedure.
Module Module1
Sub Main()
Dim num As Integer
Console.WriteLine("Enter Number")
num = Console.ReadLine()
reverse(num)
Console.ReadLine()
End Sub
Sub reverse(ByVal num As Integer)
Dim number = num
Dim result As Integer
While number > 0
GUI Application Development using VB.Net (22034) Page 3
Practical No. 15: Write a program to demonstrate use of Sub-procedures and parameterized
Sub-Procedure.
num = number Mod 10
result = result * 10 + num
number = number \ 10
End While
Console.WriteLine("" & result)
End Sub
End Module
OUTPUT:
Enter Number
123
Reverse Number =321
GUI Application Development using VB.Net (22034) Page 4