I use the other way of declaring optional parameters, by setting them a default value:
Public Function Middle(extends s as String, start as integer, Length as Integer = -1) as String
If Length = -1 then Length = s.len
return s.mid( start, Length)
Thanks, but that wasn’t the problem. The problem was that I don’t know if the Middle method is called with ONE or TWO parameters, so in the wrapper method you can’t call mid using Optional or a value that might not be there - you can only do that in the method signature.
Public Function Middle(extends s as String, start as integer, Optional Length as Integer)
Public Function Middle(extends s as String, start as integer, Length as Integer = -1)
are nearly identical, and both set Length to be optional,
The only difference is the first will have a length value = 0
The second will have it set to -1
In neither can you really tell if the user called the method with the optional value = the default in the signature
ie/ you cannot in either case tell if they wrote
dim s as string
dim m as string = s.Middle(0,0) // or dim m as string = s.Middle(0)
OR
dim m as string = s.Middle(0,-1) // or dim m as string = s.Middle(0)
It WILL exist since its not an reference type that can be nil