CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 1999
    Posts
    1

    Help: Function Declaration?

    I think that this fits under function declarations:

    I've got a function declared as :

    function DoOneOrTheOther (Optional One as String, Optional Other as string) as Boolean

    This function is only meant to do one of the two calculations specified by string, the two calculations requiring different initializations within the function. I want to make sure that the user sends at least one of the two parameters down. How do I do that (I mean without error checking , if statement based code)

    Thanx!


  2. #2
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Help: Function Declaration?

    Hi

    When you have optional parameters, you used to be able to count on (in VB4) anyway, the 'IsMissing' keyword (it's pretty dumb under vb5).

    You can however check the strings to see if either is empty.

    eg.


    Function DoOneOrTheOther(optional One as string, optional Other as string) as Boolean

    If len(One) = 0 And len(Other) = 0 then
    '
    ' Both are missing or empty - do something
    '
    Exit Function
    End If

    If len(One) > 0 then
    '
    ' Do something with parameter One
    '
    Exit Function
    End IF

    If len(Other) > 0 then
    '
    ' Do Something with parameter two
    '
    Exit Function
    End If

    End Function






    Regards


    Chris Eastwood






    CodeGuru - the website for developers
    http://www.codeguru.com/vb

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured