Array Problems
Arrays are used in many programs and are prone to problems.
Let's take a look at the small example
Open VB6 and create an ActiveX dll project. Change project name to fcom and class name to FC4
Choose> Tools> Add process.
Enter acceptarray1 in the name, type selection subroutine, range selection public, and then confirm
Operation again: Enter acceptarray2 in the name, select a function as the type, select public as the range, and click OK.
'Function: Pass the array address to the component, use the byref keyword, and assign a value to return
Public sub acceptarray1 (byref varray as variant) as Variant
Varray (0) = "tornado"
Varray (1) = "20"
End sub
'Function: returns a string array.
Public Function acceptarray2 () as Variant
Dim A (2) as Variant
A (0) = "tornado"
A (1) = "20"
Acceptarray2 =
End Function
OK, a component is ready. Click the menu> File> Generate the fcom. dll file.
OK. The fcom. dll file will appear in the directory.
Test
Open visual interdev6.0 and 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 ()
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 and execute the ASP file in IE. The result is as follows:
Tornado
20
Tornado
20
Summary:
String, which is returned by passing the value or as the return value.
If the parameter is passed by reference, set the parameter type to variant. This can avoid some errors. However, try to reduce the number of reference parameters
To be continued