1

Classic asp:

sub a

aryaa(0,0)=1
aryaa(0,1)=2

end

how to call this array in script function, and how to make this vbscript array to javascript array.

Please help me out from this, since 3 days i m searching for this.

Thanks.

6
  • 2
    Do you have any code you can post. you will get a more meaningful answer then Commented Dec 9, 2011 at 5:09
  • 1
    Please post what you have tried. Or at the very least post your vbScript array code. Commented Dec 9, 2011 at 5:11
  • 1
    ...and have you already read up on javascript arrays? One place to start: developer.mozilla.org/en/JavaScript/Reference/Global_Objects/… Commented Dec 9, 2011 at 5:14
  • this may be helpful to you wiki.mcneel.com/developer/scriptsamples/arrays Commented Dec 9, 2011 at 5:17
  • yesterday i tried with this but not able to use it properly.. Commented Dec 9, 2011 at 5:21

3 Answers 3

5

Suppose MY VBScript array is aryATTPlans than the below code describe ( VBScript array to Javascript array)

// this is client JS code
var aryATTPlans = new Array();  
var aryATTPlans = new Array(2); 
var i, j;
<%
' this is server VBS code
If IsArray(aryATTPlans) Then
    j=0
    For i = 0 to ubound(aryATTPlans)
        %>
        aryATTPlans[<%= i %>] = new Array(2);
        aryATTPlans[<%= i %>][<%= j %>] = <%= aryATTPlans(i, j) %>;
        <% 
    Next // i
End If 
%> 
Sign up to request clarification or add additional context in comments.

Comments

2

In Javascript you don't have a native Matrix object type. But you can use either Object or Array such as:

<script type="text/javascript">
    var aryaa = [ [1, 2] ];
    // aryaa[0][0] = 1
    // aryaa[0][1] = 2
</script>

I hope you find this useful. Check MDN documentation anyway.

Comments

2

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

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;
    }
}

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.