VB.Net program to create a user-defined function to add two integer numbers

Here, we are going to learn how to create a user-defined function to add two integer numbers in VB.Net?
Submitted by Nidhi, on December 13, 2020

Here, we will create a user-defined function that will accept two integer numbers as an argument and return the addition of arguments to the calling function or sub-routine.

Program/Source Code:

The source code to create a user-defined function to add two integer numbers is given below. The given program is compiled and executed successfully.

'VB.Net program to create a user-define function 
'to add two numbers.

Module Module1
    Function AddNum(ByVal num1 As Integer, ByVal num2 As Integer) As Integer
        Dim num3 As Integer = 0

        num3 = num1 + num2
        AddNum = num3
    End Function

    Sub Main()
        Dim num1 As Integer = 0
        Dim num2 As Integer = 0
        Dim num3 As Integer = 0

        Console.WriteLine("Enter number1: ")
        num1 = Integer.Parse(Console.ReadLine())

        Console.WriteLine("Enter number2: ")
        num2 = Integer.Parse(Console.ReadLine())

        num3 = AddNum(num1, num2)
        Console.WriteLine("Addition is: {0}", num3)
    End Sub
End Module


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


In the above program, we created a module Module1 that contains a sub-routine Main() and a user define function 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() function.

The AddNum() is the user-defined function that accepts two integer arguments and returns the addition of arguments to the Main() subroutine, then the output will be printed 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.