ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Is there "pointer to a function" in VBA (https://www.excelbanter.com/excel-programming/286081-there-pointer-function-vba.html)

Jag Man

Is there "pointer to a function" in VBA
 
In many languages you can work with pointers to functions, allowing you to
"parameterize" your code with regard to the functions that get called.
Is there a facility to do this in VBA? For example, I'd like to do something
like this:

Sub functionOne( ByRef theFunction())
....
theFunction()
....
End Sub


TIA

Ed



Vasant Nanavati

Is there "pointer to a function" in VBA
 
You can do it with th ename of the procedure as a String:

Sub Sub2(SubName As String)
Application.Run SubName
End Sub

Sub Sub1()
Debug.Print "Hello, World!"
End Sub

In the Immediate Window:

Sub2("Sub1")
Hello, World!

--

Vasant

"Jag Man" wrote in message
...
In many languages you can work with pointers to functions, allowing you

to
"parameterize" your code with regard to the functions that get called.
Is there a facility to do this in VBA? For example, I'd like to do

something
like this:

Sub functionOne( ByRef theFunction())
...
theFunction()
...
End Sub


TIA

Ed





Tom Ogilvy

Is there "pointer to a function" in VBA
 
If xl2000 or later, look at Addressof in help and see if that is what you
want. Generally, VB does not do pointers.

--
Regards,
Tom Ogilvy

Jag Man wrote in message
...
In many languages you can work with pointers to functions, allowing you

to
"parameterize" your code with regard to the functions that get called.
Is there a facility to do this in VBA? For example, I'd like to do

something
like this:

Sub functionOne( ByRef theFunction())
...
theFunction()
...
End Sub


TIA

Ed





Jag Man

Is there "pointer to a function" in VBA
 
Thanks, Vasant . I think the syntax is:
Application.Run(SubName, arg, arg)

I got a compiler syntax error with
Application.Run SubName(arg, arg)

Ed



"Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message
...
You can do it with th ename of the procedure as a String:

Sub Sub2(SubName As String)
Application.Run SubName
End Sub

Sub Sub1()
Debug.Print "Hello, World!"
End Sub

In the Immediate Window:

Sub2("Sub1")
Hello, World!

--

Vasant

"Jag Man" wrote in message
...
In many languages you can work with pointers to functions, allowing you

to
"parameterize" your code with regard to the functions that get called.
Is there a facility to do this in VBA? For example, I'd like to do

something
like this:

Sub functionOne( ByRef theFunction())
...
theFunction()
...
End Sub


TIA

Ed








All times are GMT +1. The time now is 02:52 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com