[Gambas-user] Optional and Param (Gambas 3)
Benoît Minisini
gambas at ...1...
Thu Jun 10 14:24:15 CEST 2010
> On 10/06/10 15:38, Charlie Reinl wrote:
> > Am Donnerstag, den 10.06.2010, 14:37 +0800 schrieb Werner:
> >> I'm trying to implement a simple class that creates a Float[3] array. I
> >> would like to give the user of the class an optional opportunity to fill
> >> the array with data when the class is instantiated.
> >>
> >> ----------------------------------------
> >> ' Gambas class file
> >> ' Vector3f Class
> >>
> >> Public v As New Float[3]
> >>
> >> Public Sub _new(Optional x As Float, y As Float, z As Float)
> >>
> >> If Param.Count > 0 Then v[0] = x
> >> If Param.Count > 1 Then v[1] = y
> >> If Param.Count > 2 Then v[2] = z
> >>
> >> End
> >> ---------------------------------------
> >>
> >> The above does not work because Param.Count is always 0 no matter if
> >> parameter values are supplied or not. My guess is that's because
> >> Optional can only be used from the second parameter onwards (why?).
> >>
> >> How can I make this class do what it should?
> >>
> >> Thanks
> >> Werner Dahn
> >
> > Salut Werner,
> >
> > where Param is filled? , what is Param ? an array? the class ?
> >
> > for Optional, I do not know if it can be chained like you do.
> > But it can be used also on the first Parameter.
>
> Param is a Gambas Class. It can be used to find out how many parameters
> are supplied to a routine. It's just the way my example is written it
> always gives a Count of zero, no matter how many parameters are actually
> supplied.
> http://gambasdoc.org/help/comp/gb/param
>
>
> Regards
> Werner
>
Param is only useful inside a method that takes a "variable number of
arguments", i.e. whose argument list ends with "...".
You cannot use it for optional arguments. Maybe the documentation is not clear
enough, as you thought that.
Optional arguments that are not passed by the caller just take their default
value.
Regards,
--
Benoît Minisini
More information about the User
mailing list