Results 1 to 3 of 3

Thread: Recursive vs. CallBack

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    247
    What is the difference with "recursive" function and "callback" function?
    Mako Shark
    Great White

  2. #2
    Guest
    A recursive function is one that calls itself eg:

    Code:
    Public Function foo(arg as Variant)
        'do some stuff (like the exit case)
        foo(arg)
    Next Function
    It has no reference point ot the function that called it.

    On the other hand a call back function knows which function called it, and can talk back to that function (its a bit of a theoretical concept, and I can't provde a decnt sample)

    - gaffa

  3. #3
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Just like gaffa said a recursive function calls itself. The most usual example is a function that count the faculty of a number:
    Code:
    Public Function Faculty(Number As Integer) As Long
        'The facutly of 1 or 0 is 1
        'so that's the exit point
        If Number = 1 Or Number = 0 Then
            Faculty = 1
            Exit Function
        End If
        Faculty = Number * Faculty(Number - 1)
    End Function
    A call back function is when you pass a pointer to a function as an argument to an other function.
    The function you call in turn calls the function you pass as an argument.
    A lot of API functions use callback functions. A few of them is:[*]EnumWindows[*]EnumChildWindows[*]EnumTimeFormats[*]EnumClipboardFormats[*]...and so on...

    Before VB5 you couldn't use any of these functions because VB didn't have a way for passing a function pointer.
    But Microsoft introduced the AddressOf keyword in VB5.

    Best regards

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