Code:
'Console Compiler 5.0 Example #Compile Exe 'CBox.bas An adaptation of Ivor Horton's examples from his "Beginning Visual C++ 6". #Dim All 'Shows Override of Volume() Method in inherited CBox Class. Class CBox Instance m_dblLength, m_dblWidth, m_dblHeight As Double Interface ICBox : Inherit IUnknown 'Can use Property Get/Set Property Get Length() As Double 'Methods to initialize Property=m_dblLength 'length, width, and End Property 'height dimensions. Property Set Length(Byval dblLength As Double) m_dblLength=dblLength End Property Property Get Width() As Double Property=m_dblWidth End Property Property Set Width(Byval dblWidth As Double) m_dblWidth=dblWidth End Property Property Get Height() As Double Property=m_dblHeight End Property Property Set Height(Byval dblHeight As Double) m_dblHeight=dblHeight End Property Method MakeBox(dblLength As Double, dblWidth As Double, dblHeight As Double) m_dblLength=dblLength 'One can also create a m_dblWidth=dblWidth 'Method to set all the m_dblHeight=dblHeight 'sides all at once. End Method Method Volume() As Double 'This member function Method=m_dblLength * m_dblWidth * m_dblHeight 'will return the gross End Method 'volume of a box. End Interface End Class Class GlassBox 'Lets say you are in the packaging business Interface IGlassBox : Inherit CBox, ICBox 'and need to package fragile glasses where Override Method Volume() As Double '20% of the box will be taken up with soft Method=MyBase.Volume() * 0.80 'filler packaging material to cushion the End Method 'glasses. You can utilize all the existing End Interface 'functionality of the CBox class and just End Class 'override the Volume() Method to reduce the 'effective volume by 20%. Function PBMain() As Long Local box1 As ICBox Local box2 As IGlassBox Print "box1: a regular box":Print "=============================" box1=Class "CBox" box1.Length=3.0 box1.Width=4.0 box1.Height=5.0 Print "box1.Length="box1.Length() Print "box1.Width="box1.Width() Print "box1.Height="box1.Height() Print "box1.Volume="box1.Volume() Print Print "box2: a box for glasses":Print "=============================" box2=Class"GlassBox" box2.MakeBox(3.0,4.0,5.0) Print "box1.Length="box1.Length() Print "box1.Width="box1.Width() Print "box1.Height="box1.Height() Print "box2.Volume="box2.Volume() Waitkey$ PBMain=0 End Function