-
Jun 9th, 2021, 01:59 PM
#1
Thread Starter
Member
Can the address of a VB Function be used to execute the function in some way?
Hi,
Outside of an Events context, can the address of a function obtained with GetRef(), be used in a variable which will later be used to execute the function?
What I'm trying to accomplish is sending the function name as parameter on the command line, and then executing that function inside the script, something like:
WScript test.vbs "FirstFunction"
Code:
'**** Test.vbs
Option Explicit
Function ExecuteFunction( FunctionName )
Dim RetVal
RetVal = RunThis( &Function )
ExecuteFunction = RetVal
End Function
' **** All defined functions ****
Function FirstFunction
...
End Function
Function SecondFunction
...
End Function
'*** End of test.vbs ***
-
Jun 9th, 2021, 02:08 PM
#2
Thread Starter
Member
Re: Can the address of a VB Function be used to execute the function in some way?
It looks like the answer might be Eval(). Or get the address with GetRef, then Call the variable with parentheses.
I'll play with those.
Last edited by VBExplorer12; Jun 9th, 2021 at 02:11 PM.
-
Jun 9th, 2021, 03:32 PM
#3
Re: Can the address of a VB Function be used to execute the function in some way?
GetRef returns an IDispatch (an Object) with only a default method implemented which can be called with parentheses like this
Code:
Option Explicit
Dim oFunctor
Set oFunctor = GetRef(WScript.Arguments.Item(0))
oFunctor(WScript.Arguments.Item(1))
' **** All defined functions ****
Function FirstFunction(Param)
WScript.echo "Enter FirstFunction w/ Param=" & Param
End Function
Function SecondFunction(Param)
WScript.echo "Enter SecondFunction w/ Param=" & Param
End Function
Then try on the command line something like this
c:> cscript aaa.vbs FirstFunction 123
cheers,
</wqw>
Last edited by wqweto; Jun 10th, 2021 at 01:00 PM.
-
Jun 10th, 2021, 07:50 AM
#4
Thread Starter
Member
Re: Can the address of a VB Function be used to execute the function in some way?
Thanks wq,
I had a problem using the GetRef, when applied to a function. It returned the value of the function, rather than an address.
At any rate, Eval() is working perfectly.
Thanks for the tips, I'll put those in the pim.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|