How to write COM components with VB6 (RPM)

Source: Internet
Author: User
Tags object model
Fortunately, we can use COM components to maximize the functionality of the ASP. You know, anything that can be written in a language such as VB,VC and VJ and other programming languages can be applied to the development of your Web site, which is COM (Component Object model). COM can be used to write objects that can be invoked by ASP. When the programming environment such as VB to complete the compilation of components, it can be placed in the ASP page is called by the ASP. In this article, we'll see how to use VB6 to write a COM object, how to register it on a server, and call it on an ASP page. But before I start, let me briefly introduce a little knowledge about COM.
A COM object typically behaves as a. dll file and is a compiled executable program. This means that COM is running much faster than pure ASP code. Before you can invoke a COM object, you must register it on the machine that is running the IIS server, and you cannot register the COM components through ASP code, which means that you must have permission to use the server.
Now let's take a look at what we're going to accomplish: we need to create a component that, when you pass a year on it, can tell you whether it's a leap year. Of course, this task can be done in VBScript. Here's a simple example, just for the sake of simplicity of the program, to focus more on how to create components and how to interact with ASP. In fact, as mentioned above, you can use any of the features of VB to create this component.
The first thing to do is to write an ActiveX DLL build, and as to how to call it in ASP, we'll mention it later. When you open visual Basic, a dialog box prompts you to choose a new project type, which of course selects "ActiveX DLL."
If the engineering browser is not open, you can open it by selecting the View | Engineering browser above the menu bar. If the property window is not open, the same method can open the Properties window.
Now click Project1 in the Engineering browser, and then in the Properties window you can see the project's Name property is Project1 and change it to checkyear. Of course, if you are lazy, you can also keep these default settings, just in the back of the ASP to call it, also use the appropriate engineering name and class name.
Now in engineering, a default class has been built, and you can rename it to your liking. Name the class here as Leapyear.
Fill in the following code in the class:
Option Explicit
' A function used to determine whether a year is a leap years
Public Function isleapyear (yr as Variant) as Boolean
' If the year can be divisible by 4 and not divisible by 100, or divisible by 400
' Then it's a leap year.
If (yr mod 4 = 0 and yr mod < > 0) Or yr mod = 0 Then

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.