properties - 获取VB元素的属性

标签 properties vbscript element

如何在 VB 脚本中查看元素具有哪些属性?例子:

Dim list : Set list = CreateObject( "Scripting.Dictionary" )
' ... Fill List ...
WriteListElements list
...

Sub WriteListElements ( list )
    Dim e, le
    For Each e In list
        Set le = list(e)                  ' what properties does le have?
        le.name_of_user_defined_attribut  ' I want to access a property but dont know the exact name
    Next
End Sub

我使用带有 VBScript API 的工具。在该 API 中,我可以从该工具读取(用户定义的)属性。但是在运行脚本时,我收到一个错误,告诉我它不知道该用户定义的属性的名称。但我在工具中使用它。现在我想知道上面的数组中有哪些属性可用,以查看用户定义的属性是否被具体命名。

最佳答案

不太可能。 VBScript 运行时中只有非常基本的类型信息可用。理想情况下,您可以创建一个适配器,将您的工具对象转换为标准 Dictionary 对象并迭代键。如果这是不可能的,您能做的最好的事情就是在调用其成员之前检查每个对象的类型名称。例子:

<html>
<body>

<script type="text/vbscript">

    Class Human
        Private m_name

        Public Property Get Name
            Name = m_name
        End Property

        Public Property Let Name(newName)
            m_name = newName
        End Property
    End Class

    Dim joe 
    Set joe = new Human
    joe.Name = "Joe Coder"

    Dim list
    Set list = CreateObject( "Scripting.Dictionary" )
    list.Add "a", 5
    list.Add "b", joe
    list.Add "c", "apples"

    WriteListElements list

    Sub WriteListElements ( list )
        Dim e
        For Each e In list
            If (TypeName(list.Item(e)) = "Human") Then
                document.write("We have found a Human: " &_
                    "<b>" & list.Item(e).Name & "</b>")
            End If
        Next
    End Sub

</script>

</body>
</html>

关于properties - 获取VB元素的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12569931/

相关文章:

tomcat - web.xml:从属性文件设置值

c# - 返回字符串的最佳方式

javascript - VBS - IE - 单击 javascript 弹出窗口上的 "OK"的脚本

batch-file - 如何关闭不可见的VBS文件

jquery - 高度在 jQuery 中返回元素的 0

asp.net - 当 TextBox 位于 CreateUserWizard 控件中时,为什么我无法通过 ID 引用它?

javascript - 为什么 `HTMLelement.innerText` 添加换行符(\n)?

ios - 在 'tag' 类型的对象上找不到属性 '_strong id'

python - 在 SQLAlchemy 中查询混合属性

vbscript - 有人可以解释一下我的 VBScript 错误吗