"excel vba pass array to and from script control" Code Answer's
You're definitely familiar with the best coding language VBA that developers use to develop their projects and they get all their queries like "excel vba pass array to and from script control" answered properly. Developers are finding an appropriate answer about excel vba pass array to and from script control related to the VBA coding language. By visiting this online portal developers get answers concerning VBA codes question like excel vba pass array to and from script control. Enter your desired code related query in the search bar and get every piece of information about VBA code related question on excel vba pass array to and from script control.
excel vba pass array to and from script control
'VBA for passing arrays to and from JScript in the Script Control.
'JScript, running in the Microsoft Script Control, can be
'passed VBA safearrays... exactly the same as Internet Explorer can
'be. But before JScript can do anything with the values in the
'VBA foreign array, a new JScript array must be created based
'on the VBA safearray:
vA = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
With CreateObject("ScriptControl")
.Language = "JScript"
.AddCode "function jsArray(v){return new VBArray(v).toArray()}"
.AddCode "function sum(v){for(var a=jsArray(v),r=0,t=0;t<a.length;t++)r+=a[t];return r};"
MsgBox .Run("sum", vA) '<--displays: 55
End With
'2D arrays and higher are converted to zero-based 1D JScript arrays
'by VBArray().toArray().
'Resource:
' https://developer.mozilla.org/en-US/docs/Web/JavaScript/Microsoft_Extensions/VBArray
'-------------------------------------------------------------------------------------------
'Attempting to return a JScript array from the Script Control
'results in a comma delimited string passed to the VBA side.
'To return the actual array to VBA instead of a string, the array
'must first be converted to a VBA array. This can be done by
'utilizing the .items() property of the Scripting Dictionary:
vA = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
With CreateObject("ScriptControl")
.Language = "JScript"
.AddCode "function jsArray(v){return new VBArray(v).toArray()}"
.AddCode "function vbArray(t){for(var r=new ActiveXObject('Scripting.Dictionary'),e=0;e<t.length;e++)r.add(e,t[e]);return r.items()}"
.AddCode "function roundTrip(v){return vbArray(jsArray(v))'}"
MsgBox UBound(.Run("roundTrip", vA)) '<--displays: 9
End With
Source: academy.excelhero.com
All those coders who are working on the VBA based application and are stuck on excel vba pass array to and from script control can get a collection of related answers to their query. Programmers need to enter their query on excel vba pass array to and from script control related to VBA code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about excel vba pass array to and from script control for the programmers working on VBA code while coding their module. Coders are also allowed to rectify already present answers of excel vba pass array to and from script control while working on the VBA language code. Developers can add up suggestions if they deem fit any other answer relating to "excel vba pass array to and from script control". Visit this developer's friendly online web community, CodeProZone, and get your queries like excel vba pass array to and from script control resolved professionally and stay updated to the latest VBA updates.