In this example, the ActiveX DLL file is created through VB5.0, which simulates a rolling process.
Create a project and double-click the ActiveX dll icon in the new project window. VB automatically adds a class module for the project and sets the project type to ActiveX DLL. In the Properties window, change the class module name attribute to clsdice. From the project menu, select project properties and change the project name to mydll. From the File menu, select Save clsdice to save the class module as mydice. Cls. Add the following
Code :
Option explicit
Private Max, point as integer
Public property get result () as integer
Result = point
End Property
Public property get maxpoint () as integer
Maxpoint = max
End Property
Public property let maxpoint (Num as integer)
Max = num
End Property
Public sub throw ()
Randomize
Point = int (RND * max) + 1
End sub
Private sub class_initialize ()
Max = 6
End sub
This class module defines two attributes and a method of the clsdice object. These attributes and methods simulate the rolling process. The maxpoint attribute indicates the number of shards, and the addition of the property let statement enables the customer to modify the number of shards. The result attribute indicates the number of rollback points. The throw method indicates the rollback action; the private sub class_initialize statement sets the number of partitions to six by default.
From the File menu, select generate mydll. dll and save it to the appropriate place. So far, we have created a DLL file of our own.
The second step is to reference the clsdice class in the ASP file.
all codes of ASP (Active Server Pages on the Active Server Page) are run on the server. You can only view the results returned in HTML format. It uses the "<%" and "%>" tags to identify the script code and does not return the code back to the client. Outside the code, it uses HTML tags to identify the content. In the following dice. the Createobject function is used in ASP code to create a clsdice object instance. The object comes from the ActiveX created above. DLL--MYDLL.DLL file, the following example uses the VBSCRIPT script language.
'load the Type Library specified in the metadata label. PATH is mydll. DLL storage path on the machine
Use DLL in ASP
<%
on error resume next 'continue execution when an unexpected error occurs in the Program
If request. Form ("T1") = "" then
Session ("point") = 6
Else
Session ("point") = request. Form ("T1 ")
End if
'Use SESSION ("point") to store the number of partitions
Set dice1 = server. Createobject ("mydll. clsdice ")
'Use the set statement to create a dice1 object. mydll is the project name when the DLL file is created above (Note: it is not the file name), and clsdice is the class module name. Now we can use the maxpoint, result, and throw attributes (methods) to operate dice1 objects.
If request. servervariables ("request_method") = "Post" then
Dice1.maxpoint = SESSION ("point") 'sets the number of partitions
Dice1.throw
%>
<Form method = "Post" Action = "dice. asp">
<P> when the number of partitions is <input type = "text" name = "T1" size = "5" value = <% = SESSION ("point ") %> hour </P>
<P> <input type = "Submit" value = "throttling" name = "B1"> </P>
</Form>
<P> result: <% = dice1.result %> point </P> 'return result
<%
Else
Dice1.maxpoint = SESSION ("point ")
%>
<Form method = "Post" Action = "dice. asp">
<P> when the number of partitions is <input type = "text" name = "T1" size = "5" value = <% = SESSION ("point ") %> hour </P>
<P> <input type = "Submit" value = "throttling" name = "B1"> </P>
</Form>
<%
End if
%>
</Body>