Results 1 to 4 of 4

Thread: How to pass a function as parameter?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2000
    Posts
    2

    Post

    Hi.
    In VB5, how can I pass a user function as
    parameter to other user function?

    Or if there is a way to pass a pointer to
    the function, how can I call it?

    Thanks in advance.



  2. #2
    Hyperactive Member
    Join Date
    Jan 1999
    Location
    Rotterdam, Netherlands
    Posts
    386

    Post

    check out the AddressOf operator
    eg.
    Call TheFunction(p1, p2, AddressOf MyFun)
    (that argument has to be declared as long)
    But you can't (at least not using straight VB code) use a pointer to call the function; it's implemented in VB to use in API calls.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2000
    Posts
    2

    Post

    I'd like to do something like...

    Function F1(x As Double) As Double
    F1 = Sin(x) * Cos(x)
    End Function

    Function F2(x As Double) As Double
    F2 = Tan(x)
    End Function

    Sub Draw(F)
    Dim x, y As Double

    For x = -10 To 10 Step 0.1
    y = F(x) 'call to passed function

    'here draw point (x,y) ...
    Next
    End Sub

    Sub DrawAll()
    Draw F1
    Draw F2
    End Sub

    I know how to do it in Delphi,
    but I'm new in VB.

    If you know how to do it,
    please let me know.
    Thanks.

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    Can you give an example of what you want to do?

    ------------------
    Marty

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