本文来自:http://www.cnblogs.com/guoxinliu_917/archive/2009/03/20/1418013.html
1. 新建一个VB EXE 工程。
Option Explicit
Public Function TestFunction() As Boolean
End Function
Option Explicit
Implements ITest
Private Function ITest_TestFunction() As Boolean
MsgBox "This is clsTest1 to implement interface ITest.",vbOKOnly,"VBInterface"
End Function
Option Explicit
Implements ITest
Private Function ITest_TestFunction() As Boolean
MsgBox "This is clsTest2 to implement interface ITest.","VBInterface"
End Function
5. 添加一个窗体,命名为frmMain,在窗体上放置两个Button,并命名为btnTest1,btnTest2.窗体的代码为:
Option Explicit
Private Sub cmdTest1_Click()
Dim Test1 As ITest
Set Test1 = New clsTest1
Call Test1.TestFunction
End Sub
Private Sub cmdTest2_Click()
Dim Test2 As ITest
Set Test2 = New clsTest2
Call Test2.TestFunction
End Sub
6. 运行程序,点击两个Button,就可以看到两个不同实现类的响应。
- 顶
- 0
- 踩
- 0