按F5运行程序;在弹出的属性对话框中,选中"Wait for Components to Start"(启动工程时等待创建部件),然后按[OK]按钮; 逆@风@者
这时,类就会被激活,其他程序就可使用它的功能。
再次运行Visual Basic另一个实例;
创建一个新的"Standard EXE"工程;
选择"'Project"->"References"菜单;
浏览对话框中可引用的列表项,可以发现一些额外的组件。
选中"Northwind"列表项;
Northwind就是前面创建的ActiveX工程。
单击[OK]按钮;
现在添加一些代码来使用上述工程:
在Form1表单中添加一个命令按钮;为命令按钮添加下列代码:
Dim Test As Customers Set Test = New Customers MsgBox Test.CustomerID Set Test = Nothing 该代码首先创建一个新的Customers对象,然后显示CustomerID信息,最后将Test对象置为Nothing,并关闭它。
Dim Test As Customers Set Test = New Customers Test.CustomerID = "KARLY" Test.Update MsgBox Test.CustomerID Set Test = Nothing 该代码首先设置"CustomerID"字段,然后更新记录集,最后显示出CustomerID属性,其结果应该是设置的"KARLY"。
Dim WithEvents rs As Recordset Public Event RecordsetMove() Private Sub Class_Initialize() Set rs = New Recordset rs.ActiveConnection = "Provider=Microsoft." & _"Jet.OLEDB.4.0;Data Source=C:\Program Files\" & _"Microsoft Visual Studio\VB98\Nwind.mdb;" & _"Persist Security Info=False" rs.Open "select * from customers", , adOpenKeyset, adLockOptimistic End Sub
Private Sub Class_Terminate() rs.Close Set rs = Nothing End Sub
Public Property Get CustomerID() As String CustomerID = rs("CustomerID") End Property