Home »
VB.Net »
VB.Net Programs
VB.Net program to create a sub-routine to add two integer numbers
Here, we are going to learn how to create a sub-routine to add two integer numbers in VB.Net?
Submitted by Nidhi, on December 13, 2020 [Last updated : March 07, 2023]
Creating a sub-routine to add two numbers
Here, we will create a sub-routing that will accept two integer numbers as an argument and then print the addition of both numbers on the console screen.
Program/Source Code:
The source code to create a sub-routine to add two integer numbers is given below. The given program is compiled and executed successfully.
VB.Net code to create a sub-routine to add two numbers
'VB.Net program to create a sub-routine to
'add two integer numbers.
Module Module1
Sub AddNum(ByVal num1 As Integer, ByVal num2 As Integer)
Dim num3 As Integer = 0
num3 = num1 + num2
Console.WriteLine("Addition is: {0}", num3)
End Sub
Sub Main()
Dim num1 As Integer = 0
Dim num2 As Integer = 0
Console.WriteLine("Enter number1: ")
num1 = Integer.Parse(Console.ReadLine())
Console.WriteLine("Enter number2: ")
num2 = Integer.Parse(Console.ReadLine())
AddNum(num1, num2)
End Sub
End Module
Output
Enter number1:
10
Enter number2:
20
Addition is: 30
Press any key to continue . . .
Explanation
In the above program, we created a module Module1 that contains two sub-routines Main() and AddNum().
The Main() subroutine is the entry point for the program. Here, we read two integer numbers from the user and pass them into AddNum() sub-routine.
The AddNum() is the user-defined sub-routine that accepts two integer arguments and prints the addition of arguments on the console screen.
VB.Net User-defined Functions Programs »