Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does a function in VBscript take variable number of arguments?

For example, if I have a function in VBscript:

Function sum(a, b, c)
    sum = a + b + c
End function

Now, in the main, I make two variables and pass them into the function sum as the following:

Dim a : a = 1
Dim b : b = 2
Call sum(a, b)

Will this work or not, and why? Thanks.

like image 889
return 0 Avatar asked Nov 30 '25 05:11

return 0


2 Answers

It will not work, VBScript doesn't support optional arguments.
I'd use a function that takes an array of numbers instead vary number of arguments to getting sum.

Function sum(nums)
    Dim i, out
    For i = 0 To UBound(nums)
        out = out + nums(i)
    Next
    sum = out
End function

Call sum(Array(1, 2, 3, 4))
like image 56
Kul-Tigin Avatar answered Dec 03 '25 04:12

Kul-Tigin


According to this, VBscript does not support optional arguments. You can do what they suggest and pass null values to your function.

like image 43
KSletmoe Avatar answered Dec 03 '25 05:12

KSletmoe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!