ASP Component beginner and proficient Series 8

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.