Let's make a component, a component that can generate a guid
Guid)
A guid can be expressed as a 32-character hexadecimal format. Com provides a system-level function named cocreateguid, which can be used to generate a new guid. This function relies on an algorithm similar to the information such as the unique identifier of the Computer nic and the system clock to create a guid that is unique in time and space.
Open VB6 and create an ActiveX dll project. Change project name to fcom and class name to fc8
Option explicit
Private type guid
Data1 as long
Data2 as long
Data3 as long
Data4 (8) as byte
End type
Private declare function cocreateguid lib "ole32.dll" (pguid as guid) as long
Private declare function stringfromguid2 lib "ole32.dll" (rguid as any, byval lpstrclsid as long, byval cbmax as long) as long
'Get guid code
'Parameter:
'Return value: String, a guid.
Public Function getguidcode () as string
Dim uguid as guid
Dim sguid as string
Dim bguid () as byte
Dim llen as long
Dim retval as long
Llen = 40
Bguid = string (llen, 0)
Cocreateguid ugu' converts the structure into a printable string.
Retval = stringfromguid2 (uguid, varptr (bguid (0), llen)
Sguid = bguid
If (ASC (mid $ (sguid, retval, 1) = 0) Then retval = retval-1
Getguidcode = left $ (sguid, retval)
End Function
OK, a component is ready. 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
<% @ Language = VBScript %>
<HTML>
<Body>
<%
Dim OBJ
Set OBJ = server. Createobject ("fcom. fc8 ")
Response. Write obj. getguidcode ()
Response. Write "<br>"
Response. Write obj. getguidcode ()
%>
</Body>
</Html>
Configure the virtual directory and execute the ASP file in IE. The result is as follows:
{EF7BF6F9-564C-44D9-91BF-F31695DA6298}
{C8A68CAC-A108-45A6-84F5-0BF92B9CF721}
You can refresh multiple times to see that this value is constantly changing.