gpt4 book ai didi

Excel VBA 错误 : Definitions of property procedures for the same property are inconsistent

转载 作者:行者123 更新时间:2023-12-04 00:49:01 27 4
gpt4 key购买 nike

这一定是显而易见的事情,但我被卡住了,所以也许你们可以帮助我。

考虑 VBA 自定义对象中的以下代码:

Private pSkipTrade As Boolean
Property Let SkipTrade(value As Double):
If value = 0 Then
pSkipTrade = False
Else
pSkipTrade = True
End If
End Property

Public Property Get SkipTrade() As Boolean
SkipTrade = pSkipTrade
End Property

谁能帮帮我?

提前致谢!

最佳答案

Let 参数必须与 Get 属性的返回类型匹配。参见 this .

所以需要把Property Let中的参数改成Boolean类型:

Private pSkipTrade As Boolean
Property Let SkipTrade(value As Boolean) '<--Parameter is Boolean type
pSkipTrade = value
End Property

Public Property Get SkipTrade() As Boolean
SkipTrade = pSkipTrade
End Property

然后将您在 Let 属性中的逻辑移动到使用该属性的代码中:

If price = 0 Then
SkipTrade = False
Else
SkipTrade = True
End If

关于Excel VBA 错误 : Definitions of property procedures for the same property are inconsistent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18446491/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com