Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
So much for Math 101. It's time to build a VB6 ActiveX server that makes use of more elaborate COM programming techniques. Create a brand-new ActiveX *.dll workspace named Vb6ComCarServer. Rename your initial class to CoCar, which is implemented like so:
Option Explicit ' A COM enum. Enum CarType Viper Colt BMW End Enum ' A COM Event. Public Event BlewUp() ' Member variables. Private currSp As Integer Private maxSp As Integer Private Make As CarType ' Remember! All Public members ' are exposed by the default interface! Public Property Get CurrentSpeed() As Integer CurrentSpeed = currSp End Property Public Property Get CarMake() As CarType CarMake = Make End Property Public Sub SpeedUp() currSp = currSp + 10 If currSp >= maxSp Then RaiseEvent BlewUp ' Fire event if you max out the engine. End If End Sub Private Sub Class_Initialize() MsgBox "Init COM car" End Sub Public Sub Create(ByVal max As Integer, _ ByVal cur As Integer, ByVal t As CarType) maxSp = max currSp = cur Make = t End Sub