For a long time, I want to write some component applications. During this time, I can finally write something I like.
I hope you can write your own components as you like after learning these tutorials.
Each article may not be associated, but it is only a matter of writing components.
Thank you for your criticism.
Environment: WINXP + VB6 + SP6 + visual interdev6.0
As the first article, let's first write a simple component.
The function is to add two numbers and return the result of adding them.
Open VB6 and create an ActiveX dll project. Change project name to fcom and class name to FC1
Choose> Tools> Add process.
Enter "add" in the name, select a function as the type, select public as the range, and click "OK ".
Generate the following code and we will continue to improve it.
Option explicit
Public Function add (byval A as long, byval B as long) as long
Add = a + B
End Function
OK. You can write a simple component. 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. Why should I use InterDev? Because it has the code prompt function, it is consistent with the VB IDE environment for easy writing?
<% @ Language = VBScript %>
<HTML>
<Head>
<Meta name = "generator" content = "Microsoft Visual Studio 6.0">
</Head>
<Body>
<%
Set OBJ = server. Createobject ("fcom. FC1 ")
'Note the following: because the function has a returned value, it cannot be written in the following method; otherwise, an error will be reported in IE.
'Obj. Add (3, 4)
'Error type:
'Microsoft VBScript compiler error (0x800a0414)
'The parentheses cannot be used to call subprograms.
'/XML/fc1.asp, line 9, column 12
'OBJ. Add (3, 4)
'Below is the correct method
Dim C
C = obj. Add (3, 4)
Response. Write c
%>
</Body>
</Html>
Configure the virtual directory and execute the ASP file in IE. Expected result 7 is displayed.
The first article is over. I wish you a pleasant learning experience.