Created
November 20, 2011 09:21
-
-
Save yu-tang/1380055 to your computer and use it in GitHub Desktop.
引数を取らない JScript の関数オブジェクトを実行する方法が分からない
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
' 引数を取らない JScript の関数オブジェクトを実行する方法が分からない | |
Sub Test() | |
Dim sc As New MSScriptControl.ScriptControl | |
Dim fx As Object | |
Dim s As String | |
s = "eval(function(){return x;});" | |
sc.Language = "JScript" | |
sc.AddCode "var x = 'Hello.';" | |
Set fx = sc.Eval(s) ' JScript の関数オブジェクトを取得する | |
Call DoSomething(fx) | |
End Sub | |
Sub DoSomething(CallbackFunction As Object) | |
Debug.Print CallbackFunction ' function(){return x;} <- 実行できない | |
Debug.Print CallbackFunction() ' function(){return x;} <- 実行できない | |
Debug.Print CallbackFunction(1) ' Hello. <- ダミーの引数を渡すと実行できるが… | |
End Sub |
ありがとうございます。
やっぱり素直な方法って無いんですかねー。
今のところ、ダミー引数渡すのが一番簡単な気がします…。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ちょっと妥協が必要なのですが、
s = "(function(){return {'hoge':function(){return x;}};})();"
として、
Debug.Print CallByName(CallbackFunction, "hoge", VbMethod)
とするとできました。