似乎无法将接口与 VBA 中的属性一起使用,我无法弄清楚为什么
Can't seem to use Interfaces with properties in VBA and I can't work out why
免责声明:我对 PHP、Java 和 VBA 有一点经验,但我主要是一名前端开发人员,所以 Javascript 更适合我.
我正在尝试创建一些 类 来实现 MS Access 数据库中的接口,但我什至无法让这个概念发挥作用。
我有:
IFeed Class(界面)
Option Explicit
Public Name As String
Public Property Get Name() As String
End Property
Public Property Let Name(ByVal vNewValue As String)
End Property
CFeed Class
Option Explicit
Implements IFeed
Private Name As String
Private Property Let IFeed_Name(ByVal newName As String)
Name = newName
End Property
Private Property Get IFeed_Name() As String
IFeed_Name = Name
End Property
测试模块
Public Sub testFeedClass()
Dim test As CFeed
Set test = New CFeed
test.Name = "New Feed" ' Doesn't work
Debug.Print test.Name
End Sub
我花了将近一天的时间将 private 更改为 public,将 public 更改为 private 以及大量其他内容,但我就是无法让它工作。有人可以指出我哪里出错了吗?我相信这很简单。
在 VBA 中,已实现接口的成员不会进入 class 对象本身,例如他们在 C# 中做 implicit interface implementation.
要使用已实现的接口,您需要将对象转换为该接口:
Dim test As IFeed
Set test = New CFeed
test.Name = "New Feed"
免责声明:我对 PHP、Java 和 VBA 有一点经验,但我主要是一名前端开发人员,所以 Javascript 更适合我.
我正在尝试创建一些 类 来实现 MS Access 数据库中的接口,但我什至无法让这个概念发挥作用。
我有:
IFeed Class(界面)
Option Explicit
Public Name As String
Public Property Get Name() As String
End Property
Public Property Let Name(ByVal vNewValue As String)
End Property
CFeed Class
Option Explicit
Implements IFeed
Private Name As String
Private Property Let IFeed_Name(ByVal newName As String)
Name = newName
End Property
Private Property Get IFeed_Name() As String
IFeed_Name = Name
End Property
测试模块
Public Sub testFeedClass()
Dim test As CFeed
Set test = New CFeed
test.Name = "New Feed" ' Doesn't work
Debug.Print test.Name
End Sub
我花了将近一天的时间将 private 更改为 public,将 public 更改为 private 以及大量其他内容,但我就是无法让它工作。有人可以指出我哪里出错了吗?我相信这很简单。
在 VBA 中,已实现接口的成员不会进入 class 对象本身,例如他们在 C# 中做 implicit interface implementation.
要使用已实现的接口,您需要将对象转换为该接口:
Dim test As IFeed
Set test = New CFeed
test.Name = "New Feed"