dumpsite.com
April 19, 2014, 08:23:49 pm *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: VBtoJSArray - converts a VB safe-array into a javascript array.  (Read 2827 times)
Black Bart
Newbie
*
Posts: 5


« on: July 02, 2012, 06:37:23 pm »

The following function will convert a multi-dimensional VB safe-array into a multi-dimensional javascript array.

Try it out, Let me know if you can break it.

Code:
function VBtoJSArray(vba) {

var vbarray = new VBArray(vba);

var d = vbarray.dimensions();

var dims = [];
var base = [];
var params = [];

for (var i=1; i <= d; i++) {
dims.push(vbarray.ubound(i)-vbarray.lbound(i) + 1);
base.push(vbarray.lbound(i));
params.push(vbarray.lbound(i));
}

return convertArray(new Array(dims[0]), 0);

function convertArray(ax, index) {

for (var i=0; i < dims[index]; i++) {

params[index] = i + base[index];

if (index == dims.length-1) {

ax[i] = VBArray.prototype.getItem.apply(vbarray, params);
}
else {

ax[i] = new Array(dims[index+1]);
convertArray(ax[i], index+1);
}
}
return ax;
}
}
« Last Edit: July 02, 2012, 06:41:09 pm by Black Bart » Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.13 | SMF © 2006-2011, Simple Machines LLC Valid XHTML 1.0! Valid CSS!