ASP components entry-level and proficient Series IV

Source: Internet
Author: User
Tags reference
Array problem

Arrays are used in a lot of programs and are more prone to problems

Let's take a look at a small example



Open VB6 and create a new ActiveX DLL project. Project name modified to fcom, class name modified to FC4

Click menu-> Tool-> Add process

We enter AcceptArray1 in the name, type selector subroutine, scope Select public, and then determine

Re-operation: Enter AcceptArray2 in the name, type select function, range Select public, then OK

' Function: Pass array address to component, use ByRef keyword, and assign value to return

Public Sub AcceptArray1 (ByRef Varray as Variant) As Variant

Varray (0) = "Tornado"

Varray (1) = "20"

End Sub



' function: Returns an array of strings

Public Function AcceptArray2 () as Variant

Dim A (2) as Variant

A (0) = "Tornado"

A (1) = "20"

Acceptarray2=a

End Function



OK, a component is written, click the menu-> file-> generate FCom.dll file

OK, there will be a FCom.dll file in the directory



Test

Turn on visual interdev6.0 to generate an ASP file



<%@ Language=vbscript%>

<HTML>

<BODY>

<%

Dim obj

Set obj = Server.CreateObject ("FCOM.FC4")

Dim A (2)

' Test the first component method

Obj. AcceptArray1 (a)

Response.Write A (0)

Response.Write "<br>"

Response.Write A (1)

Response.Write "<br>"

' Test the second component method

Dim b

B=obj. AcceptArray2 ()

For i=0 to UBound (b)

Response.Write B (i)

Response.Write "<br>"

Next

%>



</BODY>

</HTML>



Configure the virtual directory, in IE to execute this ASP file, the results are as follows:

Tornado
20
Tornado
20



To sum up:

String, the number is passed by value or returned as a return value

If you use reference passing, the type of the parameter is set to a Variant. Doing so can avoid some errors. But as much as possible to reduce the reference pass parameters



To be Continued



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.