简体   繁体   English

如何在vbscript中将类的属性设置为不同的类?

[英]How can you set the property of a class to a diffrent class in vbscript?

I'm trying to do something like this in vbscript 我正在尝试在vbscript中做这样的事情

Class cla
    Public a, b
End Class

Class clb
    Public c
End Class

Set mySubObj = new clb
mySubObj.c = "value_C"

Set myObj = new cla
myObj.a = "value_A"
myObj.b = mySubObj

msgBox(myObj.b.c)   

This doesn't work, basically I'm parsing an xml document, then processing a user defined map which can include vbscript, in the script the variable would be accessed like "myobj.bc" this is just a simple example but any help would be greatly appreciated. 这是行不通的,基本上我是在解析一个xml文档,然后处理一个用户定义的映射,该映射可以包含vbscript,在脚本中可以像“ myobj.bc”一样访问变量,这只是一个简单的示例,但是任何帮助都会非常感谢。

I figured out how to do this, for more details you can look here http://www.activexperts.com/vbscript-powershell-component/vbscriptclasses/ below is the code that worked for me, hope this maybe useful to someone else. 我已经知道如何执行此操作,有关更多详细信息,请参见此处http://www.activexperts.com/vbscript-powershell-component/vbscriptclasses/以下是对我有用的代码,希望这对其他人可能有用。

Class ClassA 
    Private m_A 
    Private m_B 

    Public Property Get A
        A = m_A 
    End Property 

    Public Property Let A(value) 
        m_A = value 
    End Property 

    'Since this property is and object must use 
    'Set instead of Let, and must 
    'specifically Set the values 

    Public Property Get B 
        Set B = m_B 
    End Property

    Public Property Set B(value) 
        Set m_B = value
    End Property 
End Class 

Class ClassB
    Public C 
End Class 

Set a = New ClassA
a.a = "value1" 
Set a.b = new ClassB 
a.b.c = "value2" 

MsgBox(a.b.c) 'shows "value2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM