amr*_*ama 11 oop excel vba excel-vba
我如何实现我的类ClsInterface,它具有以下代码:
Public Function add(x As Integer, y As Integer) As Integer
End Function
Run Code Online (Sandbox Code Playgroud)
在我的班级Class2,其中包含以下代码:
Implements ClsInterface
Public Function add(x As Integer, y As Integer) As Integer
add = x + y
End Function
Run Code Online (Sandbox Code Playgroud)
我的测试代码是
Public Sub test()
Dim obj As New Class2
MsgBox obj.add(5, 2)
End Sub
Run Code Online (Sandbox Code Playgroud)
这总是会出现以下错误:
Microsoft Visual Basic
编译错误:对象模块需要为接口'ClsInterface'
确定/帮助 实现'添加'
但是在Microsoft帮助上没有帮助(当我按下"帮助"按钮时).
有任何想法吗?
Ale*_* K. 14
你的Class2必须如下:
Implements ClsInterface
Private Function ClsInterface_add(x As Integer, y As Integer) As Integer
ClsInterface_add = x + y
End Function
Run Code Online (Sandbox Code Playgroud)
查看Class2代码窗口顶部的下拉框,您可以看到可以引用的基础对象; Class或ClsInterface.
在您想要的测试代码中:
Dim obj As New ClsInterface
Run Code Online (Sandbox Code Playgroud)
如果要通过界面调用.
我还建议在表单中命名接口,然后ISomeDescription使用而不是.DimSetDim As New
| 归档时间: |
|
| 查看次数: |
7023 次 |
| 最近记录: |