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