﻿'Visual Basic 2012 Optionele Argumenten - Optional Procedures en Functies Module Example1 Sub Main() Console.WriteLine(GetPower(3, 3)) Console.WriteLine(GetPower(3)) ' (1) ' Console.ReadLine() End Sub Function GetPower(ByVal base As Integer, _ Optional ByVal exponent As Integer = 2) As Integer GetPower = base ^ exponent End Function End Module Module Example2 Sub Main() ShowSum(1) ' value1 = 1 | value2 = 2 | value3 = 3 ' (1) ShowSum(2, 3) ' value1 = 2 | value2 = 3 | value3 = 3 ' (1) ShowSum(4, , 5) ' value1 = 4 | value2 = 2 | value3 = 5 ' (1) ShowSum(6, 7, 8) ' value1 = 6 | value2 = 7 | value3 = 8 ' (1) ' ShowSum(value1:=1) ' (2) ShowSum(value1:=2, value2:=3) ' (2) ShowSum(value1:=4, value3:=5) ' (2) ShowSum(value1:=6, value2:=7, value3:=8) ' (2) ' ShowSum(value3:=5, value1:=4) ' (3) ShowSum(value3:=8, value2:=7, value1:=6) ' (3) ' ShowSum(4, value3:=5) ' (4) ' Console.ReadLine() End Sub Sub ShowSum(ByVal value1 As Integer, _ Optional ByVal value2 As Integer = 2, _ Optional ByVal value3 As Integer = 3) Console.WriteLine(value1 + value2 + value3) End Sub End Module 'Bezoek www.vbvoorbeelden.be voor meer Visual Basic voorbeelden. 'Copyright - De Wolf / vbvoorbeelden - 2003-2012 - Alle rechten voorbehouden.