VB.NET tutorial-passing parameters to procedure

VB.NET Sub-procedure and Function

A sub-procedure or function can accept parameters. Parameters will be used to pass data tot the sub-procedure or function. The first example, the name of a person input by the user will be passed to the printyourname sub-procedure. In the second example, there are two values x and y that are passed to the sum2values function.


Module Module1
    Sub Main()
        Dim n As String
        Console.Write("Enter yourname:")
        n = Console.ReadLine
        printyourname(n) ' calling sub-procedure with a parameter
    End Sub

    'defining sub-procedure with a parameter
    Sub printyourname(ByVal n As String)
        Console.WriteLine("Welcome " & n & "!")
    End Sub
End Module

Module Module1
    Sub Main()
        Dim result As Integer
        Dim x, y As Integer
        Console.Write("Enter value1:")
        x = CInt(Console.ReadLine)
        Console.Write("Enter value2:")
        y = CInt(Console.ReadLine)
        result = sum2values(x, y) 'calling the function with 2 parameters
        Console.WriteLine("Result=" & result)
    End Sub
    'defining a function with 2 parameters

    Function sum2values(ByVal x, ByVal y)
        sum2values = x + y
    End Function
End Module


This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.