Consulting

Results 1 to 2 of 2

Thread: writing a function

  1. #1
    VBAX Mentor
    Joined
    Jun 2005
    Posts
    374
    Location

    writing a function

    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
    [VBA]
    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

    [/VBA]
    why do i get a zero as an answer.?
    moshe

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    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
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •