VBA复杂的Getter,Setter语法 [英] VBA Complicated Getter, Setter syntax

查看:153
本文介绍了VBA复杂的Getter,Setter语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我比较新的VBA我需要创建一个相对复杂的Getter和Setter的对象。为了做到这一点,我不断检查 MSDN ,但显然我不明白一些因为VBE保持突出显示行的开始和关闭:属性(它需要Get或Let ??),Get(它显然需要标识符),让(它显然也需要标识符)。



但是我试图遵循更简洁的符号,其中Get和Let方法属于Microsoft在其示例中使用的属性声明(参见上面的链接)。有人可以告诉我我的语法在哪里错误(或微软的文档)?



谢谢你

 私有矩阵()作为向量
属性转换()
公共获取(Old_S As String ,New_S As String,Period As Integer)As Double
'一些代码
返回矩阵(列,行).Value(Period)
结束Get
公开让(Old_S As String ,New_S As String,Vector_String As String)
'一些代码
矩阵(行,列).Value = Vector_String
结束让
结束属性


解决方案

您正在阅读VB.NET的文档。这就是为什么你感到困惑。 VBA中属性的语法不同。在VBA中,属性的 Get 不会组合在一起。它们需要单独列出,基本上就像两个单独的方法:

 私人mMyProperty As String 

公开属性Get MyProperty()As String
MyProperty = mMyProperty
结束属性

公共属性让Transition(Value As String)
mMyProperty = Value
结束属性

对于VBA参考资料,请尝试开始 here


Hi I'm rather new to VBA I need to create an object with relativelly complicated Getter and Setter. To do this I am constantly checking with MSDN but clearly I am not understanding something because VBE keep highlighting lines starting and closing: Property (it appaently needs Get or Let??), Get(it apparently needs identifier), Let(it apparently needs identifier as well).

But I am trying to follow more concise notation where Get and Let methods are within a Property Statement which is used by Microsoft in its examples(see link above).

Can someone tell me where is my syntax wrong(or Microsoft's Documentation for that matter)???

Thank you

Private Matrix() As Vector
Property Transition()
    Public Get(Old_S As String, New_S As String, Period As Integer) As Double
        ' Some Code
        Return Matrix(Column, Row).Value(Period)
    End Get
    Public Let(Old_S As String, New_S As String, Vector_String As String)
        ' Some Code
        Matrix(Row, Column).Value = Vector_String
    End Let
End Property

解决方案

You are reading the documentation for VB.NET. That's why you are confused. The syntax for properties in VBA is different. In VBA, the Get and Let for a property are not grouped together. They need to be listed separately, essentially like two separate methods:

Private mMyProperty As String

Public Property Get MyProperty() As String
    MyProperty = mMyProperty
End Property

Public Property Let Transition(Value As String)
    mMyProperty = Value
End Property

For VBA reference material, try starting here.

这篇关于VBA复杂的Getter,Setter语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆