Results 1 to 4 of 4

Thread: VBA: Using pointers to functions

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    1

    VBA: Using pointers to functions

    Hello,

    At the moment I'm programming in VBA6 for Excel 2003. I've a decent C/C++ background and wonder how I can implement the following in VBA:

    I want to declare a function, which accepts a pointer to another function as an argument, and then is able to call this pointed function.

    An example in C:

    Code:
    float myfuntion(void (*inputfunction)(float, float*, float*), float x1, float x2)
    {
    ...
    (*inputfunction)(x1, &fl, &fh)                                  // calling the function
    ...
    }
    Thank you very much for your help.

    Regards,
    Steve
    Last edited by Steve06; Mar 28th, 2006 at 03:35 PM. Reason: formatting

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: VBA: Using pointers to functions

    In short, you can't really, not like that anyway.

    What you can do, however, is use CallByName to call a function by passing a string containing its name. This does require that the function is an object method (and public, obviously).

  3. #3
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: VBA: Using pointers to functions

    I once showed how you can use CallWindowProc to be able to call functions with a pointer. The draw-back is that the function you want to call (using the pointer) must accept exactly 4 arguments. Anyway here is the CodeBank post that shows you how to do it.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: VBA: Using pointers to functions

    Excel VBA question moved to Office Development

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