只有functions
(和subs
)可以被Set functionReference = GetRef("myFunction")
引用,但不是對象。
如果你想有一個字符串引用,你必須創建一個你想引用的每個對象。您可以使用以下字典:
Dim foo, bar
Dim StringObjectReference : Set StringObjectReference = CreateObject("Scripting.Dictionary")
' Lets create some objects
Set foo = CreateObject("System.Collections.ArrayList")
Set bar = CreateObject("Scripting.Dictionary")
' Register the objects for referral, now we can reference them by string!
StringObjectReference.Add "foo", foo
StringObjectReference.Add "bar", bar
' Manipulate the objects through their string reference
StringObjectReference("foo").Add "BMW"
StringObjectReference("foo").Add "Chrysler"
StringObjectReference("foo").Add "Audi"
StringObjectReference("foo").Sort
StringObjectReference("bar").Add "Bikes", array("Honda", "Thriumph")
StringObjectReference("bar").Add "Quads", array("Honda", "Kawasaki", "BMW")
' Retrieve values from the objects
' real:
msgbox "My Cars: " & join(foo.ToArray(), ", ")
msgbox "My Bikes: " & join(bar("Bikes"), ", ")
msgbox "My Quads: " & join(bar("Quads"), ", ")
' From reference
msgbox "My Cars: " & join(StringObjectReference("foo").ToArray(), ", ")
msgbox "My Bikes: " & join(StringObjectReference("bar").Item("Bikes"), ", ")
' Shorthand notation (without item)
msgbox "My Quads: " & join(StringObjectReference("bar")("Quads"), ", ")
請退後一步,描述您嘗試解決的實際問題,而不是您認爲的解決方案。你爲什麼認爲你需要這個?什麼? –
即使你不想退後一步並描述問題 - 試着理解你自己的問題,並向我們解釋它,因爲它完全不清楚你在說什麼。 – TheBlastOne
你說得對,我的例子沒有任何意義。我糾正了它。所以問題在於,我在HTA中填充了2個不同來源的2個不同字典,但是希望能夠使用基於用戶選擇構建出Div的innerhtml的相同功能。將參數(字典對象名稱)傳遞給函數以確定要使用的對象,而不是使用if語句,並將所有代碼寫入HTML ...每個字典一次。問題是關於VB中的動態引用,如可以在html中使用getobjectbyid() – user3023537