Array problem
A lot of uses in the program, and more prone to problems
Let's take a look through a small example.
Open VB6, create a new ActiveX DLL project. The engineering name is modified to FCOM, the class name is modified to FC4
Click on the menu -> Tool -> Add Procedure
We enter an AcceptArray11 in the name, the type selection subroutine, the range selection, and then determine
Opening again: Enter the AcceptArray2 in the name, the type selection function, the range selection, and then determine
'Features: Pass array addresses to components, use the Byref keyword, and return
Public Sub AcceptArray1 (byref variant) as variant
Varray (0) = "Tornado"
Varray (1) = "20"
End Sub
'Features: Returns a string array
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 on the menu -> File -> Generate the FCOM.dll file
Determine, there will be an FCOM.dll file in the directory.
test
Open Visual InterDev6.0 to generate an ASP file
<% @ Language = VBScript%>
<%
DIM OBJ
Set obj = server.createObject ("FCOM.FC4")
DIM A (2)
'Testing the first component method
Obj.acceptarray1 (a)
Response.write a (0)
Response.write "
"
Response.write a (1)
Response.write "
"
'Testing the second component method
DIM B
B = obj.acceptArray2 ()
For i = 0 to Ubound (b)
Response.write B (i)
Response.write "
"
NEXT
%>
Body>
Html>
Configure a virtual directory, perform this ASP file in IE, resulting in the following:
Tornado 20 tornado 20
in conclusion:
String, digital pass value passed or as a return value is returned
If you use a reference delivery, the type of parameters is set to Variant. This can avoid some errors. However, the reference transmission parameters are reduced as much as possible.
Last continued