You are here: Reference > JavaScript > core > objects > VBArray

VBArray object

Browser support:
This object provides access to arrays created by Visual Basic scripts.
Visual Basic arrays cannot be created with the VBArray object, and their contents cannot be modified. The VBArray object can only connect to a Visual Basic array and read its contents.

Syntax:

Creating a new VBArray object:
var vbArr = new VBArray (arrayInVB)
arrayInVB Required. Reference to a Visual Basic array.

Members:

The VBArray object inherits from the VBArray.prototype and Function.prototype objects. The following lists only contain the members of the VBArray and VBArray.prototype objects.

Properties:

Property Support Description
prototype
Returns a reference to the VBArray.prototype object. The VBArray.prototype object allows adding properties and methods to the VBArray object that can be used with instances of the VBArray object, like any predefined property or method. The prototype property is static, it cannot be accessed from an instance of the VBArray object, only VBArray.prototype is allowed.

Methods:

Method Support Description
dimensions ( )*
Returns the number of dimensions in the referenced Visual Basic array.
getItem (index1 [, index2, ...], indexN)*
Returns the elements at the specified positions from the referenced Visual Basic array.
index1 [, index2, ...], indexN Required. Specifies the positions of the required elements in each dimension.
lbound (dimension)*
Returns the lowest index in the specified dimension of the referenced Visual Basic array.
dimension Required. Integer that specifies the dimension within the array. Non zero-based, the first dimension index is 1.
toArray ( )*
Converts the referenced Visual Basic array to a standard JavaScript array.

The returned JavaScript object is always a one dimensional array regardless of the dimension count of the Visual Basic array.
The method uses backward lexicographical ordering on the indexes of the Visual Basic array for the order of the items in the JavaScript array.

For example if the Visual Basic array has 3 dimensions, and 0,1,2 indices in every dimension, the order of this element in the JavaScript array:
(0,0,0) (1,0,0) (2,0,0) (0,1,0) (1,1,0) (2,1,0) (0,2,0) (1,2,0) (2,2,0) (0,0,1) (1,0,1) (2,0,1) (0,1,1) (1,1,1) (2,1,1) (0,2,1) (1,2,1) (2,2,1) (0,0,2) (1,0,2) (2,0,2) (0,1,2) (1,1,2) (2,1,2) (0,2,2) (1,2,2) (2,2,2)
ubound (dimension)*
Returns the highest index in the specified dimension of the referenced Visual Basic array.
dimension Required. Integer that specifies the dimension within the array. Non zero-based, the first dimension index is 1.

(*) - The method is inherited from the RegExp.prototype.

Examples:

Example 1:

This example shows how you can create an array in Visual Basic script and how you can handle this array from JavaScript.
<script type="text/vbscript">
Function CreateVBArray()
    Dim a(1, 1)
    a(0,0) = "00"
    a(0,1) = "01"
    a(1,0) = "10"
    a(1,1) = "11"
    CreateVBArray = a
End Function
</script> 

<script type="text/javascript">
        // Create a VBArray
    var vbArr = new VBArray(CreateVBArray());

    var dim = vbArr.dimensions ();
    document.write ("The dimension of the Visual Basic array: " + dim);
    document.write ("<br /><br />");
    for (var i = 0; i < dim; i++) {
        var minIdx = vbArr.lbound (i + 1);  // starts from 1
        var maxIdx = vbArr.ubound (i + 1);  // starts from 1
        document.write ("The indexes of dimension " + i + ": (" + minIdx + ", " + maxIdx + ")");
        document.write ("<br />");
    }

    var item00 = vbArr.getItem (0,0);
    var item01 = vbArr.getItem (0,1);
    var item10 = vbArr.getItem (1,0);
    var item11 = vbArr.getItem (1,1);
    document.write ("<br />");
    document.write ("The items : " + item00 + ", " + item01 + ", " + item10 + ", " + item11);

            // Convert to JavaScript array format
    var jsArr = vbArr.toArray();

    document.write ("<br /><br />");
    document.write ("Length of the JavaScript array: " + jsArr.length);

    document.write ("<br />");
    document.write ("The items : " + jsArr[0] + ", " + jsArr[1] + ", " + jsArr[2] + ", " + jsArr[3]);
</script>
Did you find this example helpful? yes no

External links:

User Contributed Comments
Black Bart
Convert a multi-dimensional VB safe-array into a multi-dimensional javascript array
This function will convert a multi-dimensional VB safe-array into a multi-dimensional javascript array.

http://dumpsite.com/forum/index.php?topic=63.0

Post Content

Post Content