PDA

Click to See Complete Forum and Search --> : How to pass a function as parameter?


moreira
Jan 3rd, 2000, 10:47 PM
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.

Crazy D
Jan 4th, 2000, 12:58 AM
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.

moreira
Jan 4th, 2000, 01:50 AM
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.

MartinLiss
Jan 4th, 2000, 11:20 AM
Can you give an example of what you want to do?

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