Monday, November 08, 2010 at 12:02 AM.
system.verbs.builtins.com.callScript
on callScript (scriptCode, language, mainRoutine, parameters) { <<Run an Active Scripting Engine script. <<Parameters: <<scriptCode is the actual script. <<This script should be composed of subroutines and functions. <<language is the script's language. <<Examples: VBScript, JScript, PerlScript <<mainRoutine <<The name of the function or subroutine in the script to call. <<parameters <<A list, the parameters to pass to the script that's called. <<Note: the Microsoft Script Control is required. <<See http://msdn.microsoft.com/scripting/ local (dllPath = frontier.pathString + "DLLs\\ScriptControlDLL.dll"); <<local (dllPath = "D:\\Projects\\ScriptControlDLL\\Debug\\ScriptControlDLL.dll") local (methodName = "callscript"); local (result); local (flDebug = false); if typeOf (parameters) != listType { scriptError ("Can't call com.callScript because the last parameter must be a list.")}; if flDebug { new (outlineType, @temp.scriptControlDllTrace)}; result = dll.call (dllPath, methodName, scriptCode, language, mainRoutine, parameters); if result endsWith " COM ERROR!" { //this is our flag that an error occurred local (errorMessage); result = string.mid (result, 1, sizeOf (result) - 11); errorMessage = "Can't execute this script because the Script Control reports: \""; errorMessage = errorMessage + result + "\""; errorMessage = string.replaceAll (errorMessage, "\r\n", ""); if flDebug { edit (@temp.scriptControlDllTrace); window.zoom (@temp.scriptControlDllTrace); temp.lastErrorMessage = errorMessage}; scriptError (errorMessage)}; if flDebug { edit (@temp.scriptControlDllTrace); window.zoom (@temp.scriptControlDllTrace)}; return (result)} <<bundle //test code <<local (s = "Function MyMainRoutine (a, b)\r\nMsgBox (a)\r\nMyMainRoutine = b * 3\r\nEnd Function") <<local (x) <<x = com.callScript (s, "VBScript", "MyMainRoutine", {"Scripting is fun!", 3}) <<dialog.notify ("The returned value is " + x + ".")
This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.