+ Reply to Thread
Results 1 to 4 of 4

How to notify a function's caller of a condition.

  1. #1
    Registered User
    Join Date
    09-19-2011
    Location
    oc,ca
    MS-Off Ver
    Excel 2003
    Posts
    44

    How to notify a function's caller of a condition.

    I have a search function that returns an array. The number of elements in the array that the function returns correspond to the number of matches that the function finds.

    For example, if the function finds 5 matches, then it will use a redim statement to resize the array to 5 elements and then fill in each element with information relating to the match.

    If the function does not find any matches, what are some ways it can notify the function's caller that no matches are found? If the return value of the function is an integer, then I would just return a 0. This will let the caller know that 0 matches are found. In this case, the return value is an array which makes thing a little weird.

    Thanks,

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,662

    Re: How to notify a function's caller of a condition.

    An idea: raise an error:
    Please Login or Register  to view this content.
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    09-19-2011
    Location
    oc,ca
    MS-Off Ver
    Excel 2003
    Posts
    44

    Re: How to notify a function's caller of a condition.

    I thought about raising an err but is it a good programming practice? To me, it is not an error when a search function doesn't find what it is looking for.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: How to notify a function's caller of a condition.

    There are lots of ways to do this, and raising an error is certainly one.

    An alternative as to declare the function as a Boolean and pass a dynamic array or Variant that the function modifies if matches are found.
    Entia non sunt multiplicanda sine necessitate

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1