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.
Printable View
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.
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.
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.
Can you give an example of what you want to do?
------------------
Marty