All along, want to write some components of the application, this time can finally write a bit of their favorite things.
I hope that after learning these tutorials, you can write your own components at will.
Each article may not be related, just write some of the problems that occur during component authoring.
You are welcome to criticize
Environment: Winxp+vb6+sp6+visual interdev6.0
As a first article, let's write a simpler component
The complete function is: Enter two numbers added, return the result of the addition
Open VB6 and create a new ActiveX DLL project. Project name modified to fcom, class name modified to FC1
Click menu-> Tool-> Add process
We enter add in the name, type selection function, range Select public, then OK
Generate the following code, we continue to refine
Option Explicit
Public Function Add (ByVal A as long, ByVal B as long) as long
ADD = a + b
End Function
OK, a simple component is written, click the menu-> file-> generate FCom.dll file
OK, there will be a FCom.dll file in the directory
Test
Open Visual interdev6.0, generate an ASP file, why to use InterDev, because it has code hints, consistent with VB IDE environment, easy to write
<%@ Language=vbscript%>
<HTML>
<HEAD>
<meta name= "generator" content= "Microsoft Visual Studio 6.0" >
</HEAD>
<BODY>
<%
Set Obj=server. CreateObject ("FCOM.FC1")
' The following note, because the function has a return value, can not be written in the following way, or IE will be an error
' Obj. ADD (3,4)
' ERROR type:
' Microsoft VBScript Compiler error (0x800a0414)
' cannot use parentheses when calling a subroutine
'/xml/fc1.asp, line 9, column 12
' Obj. ADD (3,4)
' The following is the correct wording
Dim c
C=obj. ADD (3,4)
Response.Write C
%>
</BODY>
</HTML>
Configure the virtual directory, execute this ASP file in IE, get the result 7
The end of the first article, I wish you all a happy study