[Gambas-user] Optional and Param (Gambas 3)

Benoît Minisini gambas at ...1...
Fri Jun 11 03:09:08 CEST 2010


> On 10/06/10 23:37, Jussi Lahtinen wrote:
> > I'm used to do this kind of things like this:
> > 
> > Public Sub _new(Optional x As Float = -1, Optional y As Float = -1
> > ,Optional z As Float = -1)
> > 
> >  If x <> -1 Then v[0] = x
> >  If y <> -1 Then v[1] = y
> >  If z <> -1 Then v[2] = z
> > 
> > End
> > 
> > 
> > Jussi
> 
> Thanks Jussi and everyone else who replied.
> 
> My _new routine now looks like this and it does what it should do:
> 
> ------------------
> Public Sub _new(Optional x As Float = 0, Optional y As Float = 0,
> Optional z As Float = 0)
>   v[0] = x
>   v[1] = y
>   v[2] = z
> End
> ------------------
> Dirt simple, dirt cheap.
> I don't need to test the parameters any more because 0 is the default
> anyway. My problem was that I didn't know you need to specify Optional
> for each and every parameter. Come to think of it it does make sense.
> 
> Regards
> Werner
> 

Actually you should have to only specify the first optional keyword, because 
as soon as one argument is optional, all the next are optional too.

Regards,

-- 
Benoît Minisini




More information about the User mailing list