【问题标题】:Issue Creating Class with Boolean使用布尔值创建类的问题
【发布时间】:2018-11-09 05:17:06
【问题描述】:

我在创建此类时遇到问题,它表明 Set 参数无效并且在下面的代码中出现错误。我已经检查了三次,似乎找不到问题!知道为什么会发生此错误吗?

代码:

Option Explicit

Private pIsChargeable As Boolean

Public Property Set IsChargeable(value As Boolean)
   pIsChargeable = value
End Property
Public Property Get IsChargeable() As Boolean
   IsChargeable = pIsChargeable
End Property

错误:

编译错误:

同一属性的属性过程定义不一致,或属性过程有可选参数、ParamArray或无效的Set final参数

【问题讨论】:

  • Property Set 用于Object 类型变量。你需要Property Let
  • @BigBen 这似乎解决了我的问题,但又引发了另一个问题...我在此类String 中使用了另外两个变量,为什么Property Set 可以使用字符串而不是@ 987654330@?
  • 阅读 Chip Pearson 的 explanation 课程以及 Property Set documentation 可能会有所帮助。 Property Set 不适用于 String 变量。请参阅 Property Let documentation 以获取 Strings 的示例。

标签: excel vba


【解决方案1】:

Property Set 用于Object 类型变量。你正在寻找Property Let

阅读 Chip Pearson 的 explanation 课程也可能会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-03
    • 2019-06-27
    • 1970-01-01
    • 2015-09-17
    • 2013-11-28
    • 1970-01-01
    • 2011-04-18
    相关资源
    最近更新 更多