2009-03-20 VB定义接口
2009-03-20 21:54
337 查看
C#定义接口大家都接触比较多,但VB定义接口大家可能接触比较少。下面就定义VB接口,结合一个工程讲一下:
1. 新建一个VB EXE 工程。
2. 添加一个类,命名为ITest, 代码为:
Option Explicit
Public Function TestFunction() As Boolean
End Function
3. 添加一个类,命名为clsTest1,代码为:
Option Explicit
Implements ITest
Private Function ITest_TestFunction() As Boolean
MsgBox "This is clsTest1 to implement interface ITest.", vbOKOnly, "VBInterface"
End Function
4. 添加一个类,命名为clsTest2,代码为:
Option Explicit
Implements ITest
Private Function ITest_TestFunction() As Boolean
MsgBox "This is clsTest2 to implement interface ITest.", vbOKOnly, "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,就可以看到两个不同实现类的响应。
1. 新建一个VB EXE 工程。
2. 添加一个类,命名为ITest, 代码为:
Option Explicit
Public Function TestFunction() As Boolean
End Function
3. 添加一个类,命名为clsTest1,代码为:
Option Explicit
Implements ITest
Private Function ITest_TestFunction() As Boolean
MsgBox "This is clsTest1 to implement interface ITest.", vbOKOnly, "VBInterface"
End Function
4. 添加一个类,命名为clsTest2,代码为:
Option Explicit
Implements ITest
Private Function ITest_TestFunction() As Boolean
MsgBox "This is clsTest2 to implement interface ITest.", vbOKOnly, "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,就可以看到两个不同实现类的响应。
相关文章推荐
- VB定义接口
- VB定义接口
- java8新特性-接口定义增强
- C#的接口基础教程之二 定义接口
- PHP类实例教程(十九):PHP类接口的定义与规范
- RS232串行接口参数定义
- 通过接口定义Fragment之间的跳转
- 1)编写Animal接口,接口中声明run()方法; 2)定义Bird类和Fish类实现Animal接口; 3)编写Bird类和Fish类的测试程序,并调用其中的run()方法
- vb.net 接口(interface)
- Java中抽象类和接口定义
- java定义接口监听器详解
- Dubbo原理解析-代理之接口定义
- RS-422接口定义
- Android AIDL(安卓接口定义语言)基本使用方法
- 在C#中使用IDL文件,IDL是个接口定义文件
- java中接口的定义原则
- java中接口的定义与实现 http://blog.csdn.net/yjkwf/article/details/7238847
- 为XML文档的已解析版本定义了一组接口
- 接口中定义变量必须为public static final的原因
- brew接口定义宏解析 .