How to use Attributes
Open VB6 and create a new ActiveX DLL project. Project name modified to fcom, class name modified to FC2
Click menu-> Tool-> Add process
We enter myname in the name, type select attribute, range Select public, and then determine
Re-operate: Enter age within the name, type select attribute, scope to select public, and then determine
Re-operation: Enter Peopleinfo in the name, type select function, range Select public, then OK
The code is as follows:
Option Explicit
' Keep the local variable of the property value and use it only in the class
Private Mvarmyname as String
Private Mvarage as Integer
' Let-write property: This procedure assigns a value to a property. )
Public-let-age (ByVal vdata as Integer)
Mvarage = Vdata
End Property
' Get Read property (This procedure gets the value of a property.) )
Public Property Get Age () as Integer
Age = Mvarage
End Property
Public Property Let MyName (ByVal vdata as String)
Mvarmyname = Vdata
End Property
Public Property Get MyName () as String
MyName = Mvarmyname
End Property
Public Function Peopleinfo () as String
Peopleinfo = "Name:" & Mvarmyname & "Age:" & Mvarage
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>
<BODY>
<%
Set Obj=server. CreateObject ("FCOM.FC2")
Dim c
' The Let property of the component is called here
Obj.myname = "Tornado"
Obj. Age =20
C=obj.peopleinfo ()
Response.Write C
' The component's Get property is called here
Response.Write "<br>"
Response.Write Obj.myname
Response.Write "<br>"
Response.Write obj. Age
%>
</BODY>
</HTML>
Configure the virtual directory, in IE to execute this ASP file, the results are as follows:
Name: Tornado Age: 20
Tornado
20
To be Continued