Object-Oriented Programming in VB6-implement class inheritance

Source: Internet
Author: User

Specifically, VB6 cannot implement class inheritance in the true sense (for example, inheritance in C ++), but implements also provides similar functions.

 

 

We first create a class module cbase. CLs

The Code is as follows:

Private mvarbaseproperty as string

Public sub basefunction ()

Msgbox "Hello world !"

End sub

Public property let baseproperty (byval vdata as string)

Mvarbaseproperty = vdata

End Property

Public property get baseproperty () as string

Baseproperty = mvarbaseproperty

End Property

 

 

Next we will create a new type of module (cinherit. CLs). The Code is as follows, with key comments.

 

 

Implements cbase ''' note this keyword

Dim m_baseproperty as string

''''---------------------------------------------------------------------

''' The code between the dotted lines is inherited from the cbase class.

''' Note that the format is as follows: base class _ attribute name (or method name)

'''' The Declaration keyword of its method is also changed to private

Private property get cbase_baseproperty () as string

Baseproperty = m_baseproperty

End Property

Private property let cbase_baseproperty (byval vdata as string)

M_baseproperty = vdata

End Property

Private sub cbase_basefunction ()

Msgbox "inherit"

End sub

''''---------------------------------------------------------------------

''' This method inherits the class's own method.

Public sub inheritmsg ()

Msgbox "My owner MSG"

End sub

 

 

Now we create a new form for testing. We place the test code in the form_load event.

 

 

 

 

Test 1:

Dim objtest as cbase

Set objtest = new cbase

With objtest

. Basefunction

End

Set objtest = nothing

Run the program. The base is displayed, indicating that the basefunction function in CBSE is called.

 

 

Test 2:

Dim objtest as cbase

Set objtest = new cinherit

With objtest

. Basefunction

End

Set objtest = nothing

Run the program and pop up inherit, which indicates that the base function in cinherit is called.

 

 

Test 3:

Dim objtest as cinherit

Set objtest = new cinherit

With objtest

. Inheritmsg

End

Set objtest = nothing

Run the program. The my owner function is displayed, indicating that the inherited class can use its own functions or attributes.

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.