如何使用数组的 Property Let?
我对 VBS 很陌生,但看起来我无法实现最简单的事情。我想要一个在私有成员中保存数组的类。由于我想“注入”数组,因此我尝试使用 Let
功能实现“setter 方法”。
Class CPhase
Private m_AllowedTasks()
Public Property Let AllowedTasks(p_AllowedTasks)
m_AllowedTasks = p_AllowedTasks
End Property
Private Sub Class_Initialize()
ReDim m_AllowedTasks(0)
End Sub
End Class
此类的使用方式如下:
Dim allowed
allowed = Array("task1", "task2")
Dim phase
Set phase = New CPhase
phase.AllowedTasks = allowed
这会导致 Let 方法中出现“Microsoft VBScript 运行时错误 (...):类型不匹配”。我还尝试使用“ByVal”、“ByRef”的不同组合,但由于完全没有 VBS 经验,我找不到解决方案。那么我做错了什么?
非常感谢任何有用资源的提示或链接! 谢谢!
I am very new to VBS, but I am not able to implement even the simplest things, as it seems. I want to have a class which holds an array in a private member. Since I want to "inject" the array I tried to implement a "setter-method" using the Let
functionality.
Class CPhase
Private m_AllowedTasks()
Public Property Let AllowedTasks(p_AllowedTasks)
m_AllowedTasks = p_AllowedTasks
End Property
Private Sub Class_Initialize()
ReDim m_AllowedTasks(0)
End Sub
End Class
This class is used as follows:
Dim allowed
allowed = Array("task1", "task2")
Dim phase
Set phase = New CPhase
phase.AllowedTasks = allowed
This results in a "Microsoft VBScript runtime error (...) : Type mismatch" in the Let-method. I also tried using different combinations of "ByVal", "ByRef", but since having absolutely no experience with VBS I couldn't find a solution. So what am I doing wrong?
Any hints or links to helpful ressources are very appreciated!
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
罪魁祸首是
它创建了一个令人厌恶的东西 - 一个没有大小的固定数组。只需删除()即可。
创建一个(空)变体,可以将其 set=let 为有用的(可重整)数组。
The culprit is
which creates an abomination - a fixed array of no size. Just remove the ().
to create an (empty) Variant that may be set=let to an useful (redim-able) array.