PDA

View Full Version : writing a function



lior03
12-04-2008, 12:32 AM
hello
the aim of the following procedure is to allow the user not to add an input but still to get a result.if he omit the width input the function use the lengh input to return

Function addtroble(length As Long, Optional width As Long) As Long
Application.Volatile
If IsMissing(width) = True Then
addtroble = length ^ 2
Else
addtroble = length * width
End If
End Function


why do i get a zero as an answer.?

Bob Phillips
12-04-2008, 01:47 AM
Function addtroble(length As Long, Optional width As Variant) As Long
Application.Volatile
If IsMissing(width) = True Then
addtroble = length ^ 2
Else
addtroble = length * width
End If
End Function