如何在visual basic中创建具有可变数量参数的函数?恩.
x = Sum(1,2,3)
y = Sum(1,2)
Function Sum('how to declare argument here')
'Is there any special argument manipulation inside function before it is usable?
End Function
Run Code Online (Sandbox Code Playgroud)
Adr*_*der 20
Function Sum(ParamArray Vals() As Variant)
Dim intLoopIndex As Integer
For intLoopIndex = 0 To UBound(Vals)
Next intLoopIndex
End Function
Run Code Online (Sandbox Code Playgroud)
Arv*_*rvo 12
使用可选参数,例如:
Function Sum(Optional X1 As Integer=0, Optional X2 As Integer=0)
Run Code Online (Sandbox Code Playgroud)
或通用变量参数语法
Function Sum(ParamArray XArr() As Variant)
Run Code Online (Sandbox Code Playgroud)
(我可能已经搞砸了一些语法元素 - 随意纠正.)