1

I am working in VBA. I want to convert JS array to VBA array. I almost there. I am filling Array: "Classarray" successfully! However I have a problem with calling a function which will convert it to VBA Array. The function which I use is here:

Dim SortedArray As Variant
Dim jsObj As New ScriptControl
jsObj.Language = "JScript"    
With jsObj
  .AddCode _
    "var classArray = new Array();" & ArrayString & _
    "function setArray(ja) {" & _
    "var dict = new ActiveXObject('Scripting.Dictionary');" & _
    "for (var i=0;i < ja.length; i++ )dict.add(i,ja[i]);" & _
    "return dict.items();}"
  SortedArray = .Run("setArray", classArray)
End With

The problem is in line "SortedArray = .Run("setArray",classArray). I have got error "Error:5007 'lenght' is null or not an object" In debug mode when point on classarray it display "empty", but it isn't! See attached .jpg. Could you tell me what am I doing worng with .Run function?? Thanks.

enter image description here

4
  • 2
    Because the property is length, not lenght Commented Feb 8, 2017 at 14:43
  • You haven't shown us the Run() function, so how can we tell you what's wrong with it? Commented Feb 8, 2017 at 14:46
  • .Run is a method of jsObj. Commented Feb 8, 2017 at 15:09
  • Ok I wrote lenght here, but as you can see in the code it is written properly length. I think the the problem is the function doesn't see classarray... = Length is null Commented Feb 8, 2017 at 15:21

1 Answer 1

1

Ok I solved it. In function I replaced "ja" with "classarray".Sorry for posting a question which I answered by myself, I tried to find solution whole day. Anyway, may someone will use this code for his own purpose.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.