tablacus / TablacusScriptControl

Script Control for 64-bit platforms
https://tablacus.github.io/scriptcontrol_en.html
MIT License
62 stars 17 forks source link

Calling AddCode twice #14

Open unix53 opened 5 years ago

unix53 commented 5 years ago

I have a problem with the following code in VBA (MS Access 2010, 64 Bit)

Dim e As Object
Set e = CreateObject("ScriptControl")
e.Language = "JavaScript"
Call e.AddCode("function getKeys(jsonObj) {var keys = new Array(); for (var i in jsonObj) {keys.push(i);} return keys;}")
Call e.AddCode("function getProperty(jsonObj,propertyName){return jsonObj[propertyName];}")

After calling the AddCode method for the second time sometimes it has no entry in the CodeObject array and sometimes one of the two entries. When trying to invoke either one of them I get an error: Object doesn't support this property or method (438)

The code des work with Microsoft's original 32 Bit ScriptControl.

tablacus commented 5 years ago

I don't have MS Access 2010, 64 Bit. So, I tested it with JavaScript with the following code.

var e = new ActiveXObject("ScriptControl");
e.Language = "JavaScript";
e.AddCode("function getKeys(jsonObj) {var keys = new Array(); for (var i in jsonObj) {keys.push(i);} return keys;}");
e.AddCode("function getProperty(jsonObj,propertyName){return jsonObj[propertyName];}");

var jsonObj = {
    'abc': 'def',
    'ghi': 'jkl',
    'mno': 'pqr'
};

WScript.Echo(e.Run("getKeys", jsonObj).join("\n"));

WScript.Echo(e.Run("getProperty", jsonObj, 'ghi'));

I can't find problem.

>cscript test.js
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.

abc
ghi
mno
jkl

Regards,