Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

function with optional orguments

1 view
Skip to first unread message

balu

unread,
Sep 8, 2008, 4:08:00 AM9/8/08
to
dear friends
kndly tell me about how to build an function with orguments optional and if
any draw backs of such functions please.
post one such shample code please.

Arvin Meyer [MVP]

unread,
Sep 8, 2008, 10:13:17 PM9/8/08
to
"balu" <ba...@discussions.microsoft.com> wrote in message
news:4342E6ED-D514-47DA...@microsoft.com...

Here's an example of something I use:

Function CurRound(amount As Variant, Optional nearest As Double) As Currency
If IsNumeric(amount) Then
If IsMissing(nearest) Then nearest = 0.01
CurRound = Int(amount / nearest + 0.5) * nearest
Else
CurRound = 0
End If
End Function

You can use multiple Optional arguments like:

Function Whatever(A As String, Optional B As Integer, Optional, C As Double)

You can skip places if you put a comma like:

Function Whatever("Arvin", , 2.003)

you do not need a comma if you use it like:

Function Whatever("Arvin", 2)
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com


0 new messages