# Workaround for Optional parameter with value = nil?

Hello,

I am doing work on OpenGL collision detection and have a need for an optional method parameter equal to nil. Below is a simplified version of what I would like to code:

```In a pushbutton action event MyCoordinate(3,4,5) ```

```Sub MyCoordinate(x as double, y as double, z as double, x1 as double, y1 as double, z1 as double, optional distance as double = nil) If distance = nil then //Do other math End If End Sub```

The IDE provides two errors:

1. Parameter “distance” expects type Double, but this is type Nil. MyCoordinate(3,4,5)
2. Type mismatch error. A double parameter can’t have a Nil default value.

The value that the optional distance variable has at runtime is 0.00000. A distance of 0.00000 is a valid number. Is there another way or a workaround to enable a nil value? I could add another parameter that would be a boolean flag value, and was hoping that someone had a nicer workaround for an optional nil value.

Thanks

``````Sub MyCoordinate(x as double, y as double, z as double, x1 as double, y1 as double, z1 as double )
// do math that excludes distance
End Sub
Sub MyCoordinate(x as double, y as double, z as double, x1 as double, y1 as double, z1 as double,  distance as double )
// do math that includes distance
End Sub``````

Thank you! That’s exactly what I was looking for…

hello,
question about optional, this func. take a default value “eps” if missing.
xojo has not IsMissing

[code]Func(x as double, y as double , Optional eps as double)

``````If (IsMissing(eps)) then eps= 5

process...
``````

[/code]

[quote=486115:@Djamel AIT AMRANE]question about optional, this func. take a default value “eps” if missing.
xojo has not IsMissing [/quote]
The documentation for the Optional keyword has a ton of info you might be looking for http://documentation.xojo.com/api/language/optional.html

Tim,
the function must take eps=5 if omited .

func(1,2) use as default = 5
In case where fuc(1,2,10) the func() use eps = 10, instead of default value that’s what i want.

``Func(x as double, y as double , eps as double = 5.0)``