:= 用于名称结合的参数传递。参数传递通常方式是位置结合,如
Function Test(A, B, C)
调用:Test(1, 2, 3)这时 A = 1, B = 2, C =3。但有时很多参数都是可选的,只需要其中一的传递时,可采用VB独有的名称结合方式,如
Function Test([A], [B], [C])
调用 Test(C:=3),就表示C = 3,其他参数使用缺省值
:= 用于名称结合的参数传递。参数传递通常方式是位置结合,如
Function Test(A, B, C)
调用:Test(1, 2, 3)这时 A = 1, B = 2, C =3。但有时很多参数都是可选的,只需要其中一的传递时,可采用VB独有的名称结合方式,如
Function Test([A], [B], [C])
调用 Test(C:=3),就表示C = 3,其他参数使用缺省值
' If a function's arguments are defined as follows:
Function MyFunc(MyStr As String, Optional MyArg1 As _ Integer = 5, Optional MyArg2 = "Dolly")
Dim RetVal
' The function can be invoked as follows:
RetVal = MyFunc("Hello", 2, "World") ' All 3 arguments supplied.
RetVal = MyFunc("Test", , 5) ' Second argument omitted.
' Arguments one and three using named-arguments.
' If a function's arguments are defined as follows:
Function MyFunc(MyStr As String, Optional MyArg1 As _ Integer = 5, Optional MyArg2 = "Dolly")
Dim RetVal
' The function can be invoked as follows:
RetVal = MyFunc("Hello", 2, "World") ' All 3 arguments supplied.
RetVal = MyFunc("Test", , 5) ' Second argument omitted.
' Arguments one and three using named-arguments.