How to add an optional parameters/default value parameters in VB function?

How can I create a method that has optional parameters in it in Visual Basic?

Answers


Just use the optional keyword and supply a default value. Optional parameters must be the last parameters defined, to avoid creating ambiguous functions.

Sub MyMethod(ByVal Param1 As String, Optional ByVal FlagArgument As Boolean = True)
    If FlagArgument Then
        'Do something special
        Console.WriteLine(Param1)
    End If

End Sub

Call it like this:

MyMethod("test1")

Or like this:

MyMethod("test2", False)

Need Your Help

Echo Program Help

python user-input

I need some guidance on how best to run this program. Im trying to come up with a python program that accepts input from the user and prints them out until the word quit is inputted in which the pr...