Practice: VB creates COM components> calls in ASP and. net

Source: Internet
Author: User

1> Create an ActiveX dll project, rename the project to exampleproject, and rename the class to exampleclass.

2> creation method:

Option explicit

Public Function examplemethod (byval strname as string, byval iage as integer, optional byval bageemphasison as Boolean = false) as string
Dim strreturnstring as string
Strreturnstring = strname & "is over" & CSTR (iage * 365)
If bageemphasison and iage> 45 then
Strreturnstring = strreturnstring & "days old ."
Else
Strreturnstring = strreturnstring & "days old ."
End if

Examplemethod = strreturnstring

End Function

3> compile and generate exampleproject. DL

4> register it with regsvr32.

5> call in ASP:
<%

Set objref = server. Createobject ("exampleproject. exampleclass ")

Name = "silvaxia"
Age = 26
Emphasis = true

Strresult = objref. examplemethod (name, age, emphasis)

Response. Write (strresult)

Set objref = nothing

%>

6> put ASP in a virtual directory and run it.

7> call in. Net:
First Add a reference to exampleproject. DL, and then:

Module module1

Sub main ()
Testcom ()
End sub

Public Function testcom ()
Dim test as exampleproject. exampleclassclass = new exampleproject. exampleclassclass
Console. Write (test. examplemethod ("silvaxia", 67, true ))
End Function
End Module

Related Article

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.