One of ASP Component beginner and master series

Source: Internet
Author: User

For a long time, I want to write some component applications. During this time, I can finally write something I like.

I hope you can write your own components as you like after learning these tutorials.

Each article may not be associated, but it is only a matter of writing components.

Thank you for your criticism.

Environment: WINXP + VB6 + SP6 + visual interdev6.0

As the first article, let's first write a simple component.

The function is to add two numbers and return the result of adding them.

Open VB6 and create an ActiveX dll project. Change project name to fcom and class name to FC1

Choose> Tools> Add process.

Enter "add" in the name, select a function as the type, select public as the range, and click "OK ".

Generate the following code and we will continue to improve it.

Option explicit

Public Function add (byval A as long, byval B as long) as long

Add = a + B

End Function

 

OK. You can write a simple component. 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. Why should I use InterDev? Because it has the code prompt function, it is consistent with the VB IDE environment for easy writing?

<% @ Language = VBScript %>

<HTML>

<Head>

<Meta name = "generator" content = "Microsoft Visual Studio 6.0">

</Head>

<Body>

<%

Set OBJ = server. Createobject ("fcom. FC1 ")

'Note the following: because the function has a returned value, it cannot be written in the following method; otherwise, an error will be reported in IE.

'Obj. Add (3, 4)

'Error type:
'Microsoft VBScript compiler error (0x800a0414)
'The parentheses cannot be used to call subprograms.
'/XML/fc1.asp, line 9, column 12
'OBJ. Add (3, 4)

'Below is the correct method

Dim C

C = obj. Add (3, 4)

Response. Write c

%>

 

</Body>

</Html>

 

Configure the virtual directory and execute the ASP file in IE. Expected result 7 is displayed.

 

The first article is over. I wish you a pleasant learning experience.

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.