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

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 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


Enter number1:
Enter number2:
Addition is: 30
Press any key to continue . . .


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.

Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.