Function parameters in Visual Basic

Methods can also accept information through parameters. By .NET convention, parameter names always begin with a lowercase letter in any language.

Example

Module Module1

    Sub Main()

        Dim returnedValue As Integer
        returnedValue = MyFunc(100, 200)
        Console.WriteLine("sum is " & returnedValue)

        Console.ReadLine()
    End Sub

    ' ByVal Stands for passing parameters by value
    Private Function MyFunc(ByVal number1 As Integer, ByVal number2 As Integer) As Integer
        Console.WriteLine(number1)
        Console.WriteLine(number2)

        Return number1 + number2

    End Function

End Module

Output

100
200
sum is 300
Share

You may also like...