The problem of the transfer of arrays in JavaScript array and VB DLL

Source: Internet
Author: User
Tags arrays javascript array

Ladies and gentlemen: I now define a one-dimensional array in JavaScript, then call the DLL object written by VB, assign a value to this array in the DLL object, and then read the assigned array in JavaScript. How to operate.

DLL object:

Testprj.test

Public   Sub   Test (StrName ()   as   Variant)
StrName (0) = "MR"
StrName (1) = "Zhang"
End Sub

Javascript:

<script   language= ' JavaScript ' >
var a=new Array ();
var test=new activeobjectx ("Testprj.test");
Test.test (A);
Response.Write (A.length);
</Script>

Excuse me, where is the error???

---------------------------------------------------------------

Thank you for using Microsoft products.

You can create Acivexdll in VB, process functions with array parameters, and call Acivex object functions in ASP. Because the array object of JavaScript is stored in a different way from the array in VB, the JavaScript array object as an argument to the Vbactivexdll function will have an error of type mismatch. It is recommended that you use VBScript in ASP.

The following example, first in VB to establish Acivexdll project, the project name is Asparray, class name Clsarray

Public   Function   testarray (ByRef   varray   as   Variant)   as   String
Dim ncnt as Integer
' Check that ' the argument passed are an Array
If not IsArray (varray) Then
Testarray = "Parameter is isn't an Array"
Exit Function
End If
For ncnt = LBound (varray) to UBound (Varray)
' Change Array Element
Varray (ncnt) = "AQQQ"
Next ncnt
Testarray = "Parameter is an Array"
End Function

Referencing the Asparray.clsarray object in ASP,

<%
Dim otestobj, Vmyarray (2), Vrtnvalue
Vmyarray (0) = "Element 1"
Vmyarray (1) = "Element 2"
Vmyarray (2) = "Element 3"
Set otestobj = Server.CreateObject ("Asparray.clsarray")
Vrtnvalue = Otestobj.testarray (vmyarray)
Response.Write ( vrtnvalue )
%> <br>
Vmyarray (1) = <%=vmyarray (1)%>

For more information, please refer to the following links:

Howto:implementarrayargumentsinvbcomobjectsforasp

Http://support.microsoft.com/support/kb/articles/q217/1/14.asp

You can use the ToArray () method of the VBArray object in JavaScript to convert the array of VBScript (array) into a JavaScript array, but as of the current VBScript (4.0) version, There is no way to convert a JavaScript array into a VBScript array.

For more information, refer to the Passingarraysfromvbscripttojscript section of the following documentation:

Usingvbscriptandjscriptonawebpage

Http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvid/html/msdn_vbnjscrpt.asp

-Microsoft Global Technology Center VB Technical Support

This post is provided "as is" and has no warranty whatsoever and is not granted any rights. Specific items can refer to the terms of use

(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp).

To create a better discussion environment for you, please join our Customer satisfaction survey

(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key= (s,49854782)).

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.