自定义类的属性(不是集合) [英] Properties for a custom class (not a collection)
问题描述
我知道这里和.public小组已经介绍了这个,但它好像b $ b似乎已经有一段时间了,特别是在这附近,所以我只想到了
我会再问一下是否有人想出了一个新的角度。
如果我有一个class MyClass - 不是一个集合容器,而是一个
单级类 - 它有一堆不同类型的属性,
我希望能够通过标准的VBA语法来引用它们
MyClass.Properties(" MyProperty")
或
>
MyClass.Item(" MyProperty")
这样我就可以使用变量而不必说
MyClass .MyProperty
得到和让。
当然,我可以创建一个完整的系列来循环使用
项目/ IEnumerator技巧,但在我看来,那种压扁了第一版中属性的有用性ce。
提前致谢。
从Access 2000开始可以放置属性到标准模块。
可以引用它们作为ModuleName.PropertyName
示例(在一个名为PseudoClass的标准模块中)
Dim mInput As Double
公共财产让InputNumber(ByVal vInput为Double)
mInput = vInput
结束物业
公共物业获得TwelfthRoot()为双倍
TwelfthRoot = mInput ^(1/12)
结束物业
---------------------
其他地方
PseudoClass.InputNumber = 29
MsgBox PseudoClass.TwelfthRoot
''节目
''--------- ------------------
''Microsoft Office Access
''--------- ------------------
''1.32393450111241
''----------- ----------------
''确定
''---------------------------
那就是说,类的一个重要价值是可以创建多个
实例。 TTBOMK只有一个标准模块实例
可以同时存在。
同样,这些属性似乎与Subs和
功能,(也许有点慢)。
谢谢,但那不是我要问的。要使用你的例子,我想
能够做到这一点。
MsgBox PseudoClass.Properties(TwelfthRoot)
所以我可能会说
Dim strTest as string
strTest =" ThirteenthRoot"
MsgBox PseudoClass.Properties(strTest)
这是一个愚蠢的例子,但是如果你想要返回一堆
不同属性的单一一段代码,你开始看到
Class.Property是如何限制的。
以下MSDN文章展示了如何使Item属性成为集合的默认
属性。它需要使用过程属性,通常在Visual Studio 6中设置
。
http://msdn.microsoft.com/library/de...seofbricks.asp
-
David Lloyd
MCSD .NET
http://LemingtonConsulting.com
此响应按原样提供。没有任何陈述或保证。
downwitch <做******* @ gmail.com>在消息中写道
新闻:11 ********************* @ g49g2000cwa.googlegro ups.com ...
我知道这里和.public小组已经讨论了这个问题,但它好像是b $ b似乎已经有一段时间了,特别是在这附近,所以我只想到了
我会再问一下是否有人想出了一个新的角度。
如果我有一个class MyClass - 不是一个集合容器,而是一个
单级类 - 它有一堆不同类型的属性,
我希望能够通过标准的VBA语法来引用它们
MyClass.Properties(" MyProperty")
或
>
MyClass.Item(" MyProperty")
这样我就可以使用变量而不必说
MyClass .MyProperty
得到和让。
当然,我可以创建一个完整的系列来循环使用
Item / IEnumerator tr ick,但在我看来,首先要把那些物业的实用性压扁了。
提前谢谢。
Hi,
I know this has been covered here and in the .public groups, but it
seems like it''s been a while, especially around here, so I just thought
I''d ask again to see if anyone has figured out a new angle.
If I have a class MyClass--not a collection container but a
single-level class--that has a bunch of properties of different types,
I''d like to be able to reference them via the standard VBA syntax of
MyClass.Properties("MyProperty")
or
MyClass.Item("MyProperty")
so that I could use variables instead of having to say
MyClass.MyProperty
to get and let.
Of course, I could create a whole collection myself to loop using the
Item/IEnumerator trick, but seems to me that kind of squashes the
usefulness of properties in the first place.
Thanks in advance.
Since Access 2000 one can put properties into a Standard Module.
One can reference them as ModuleName.PropertyName
example (in a standard module called PseudoClass)
Dim mInput As Double
Public Property Let InputNumber(ByVal vInput As Double)
mInput = vInput
End Property
Public Property Get TwelfthRoot() As Double
TwelfthRoot = mInput ^ (1 / 12)
End Property
---------------------
somewhere else
PseudoClass.InputNumber = 29
MsgBox PseudoClass.TwelfthRoot
''Shows
''---------------------------
''Microsoft Office Access
''---------------------------
''1.32393450111241
''---------------------------
''OK
''---------------------------
That being said, one of the great values of Classes is that multiple
instances can be created. TTBOMK only one instance of a Standard module
can exist at one time.
As well, these properties seem to operate no differently than Subs and
Functions, (well maybe a bit slower).
Thanks, but that''s not what I''m asking. To use your example, I want to
be able to do this.
MsgBox PseudoClass.Properties("TwelfthRoot")
So that I could potentially say
Dim strTest as string
strTest="ThirteenthRoot"
MsgBox PseudoClass.Properties(strTest)
That''s a silly example, but if for example you want to return a bunch
of different properties with a single piece of code, you begin to see
how Class.Property is a limitation.
The following MSDN article shows how to make the Item property the default
property of a collection. It requires using Procedure Attributes, normally
set in Visual Studio 6.
http://msdn.microsoft.com/library/de...seofbricks.asp
--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com
This response is supplied "as is" without any representations or warranties.
"downwitch" <do*******@gmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
Hi,
I know this has been covered here and in the .public groups, but it
seems like it''s been a while, especially around here, so I just thought
I''d ask again to see if anyone has figured out a new angle.
If I have a class MyClass--not a collection container but a
single-level class--that has a bunch of properties of different types,
I''d like to be able to reference them via the standard VBA syntax of
MyClass.Properties("MyProperty")
or
MyClass.Item("MyProperty")
so that I could use variables instead of having to say
MyClass.MyProperty
to get and let.
Of course, I could create a whole collection myself to loop using the
Item/IEnumerator trick, but seems to me that kind of squashes the
usefulness of properties in the first place.
Thanks in advance.
这篇关于自定义类的属性(不是集合)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!