priya
priya

Reputation: 11

How to convert a string into an object in VBScript?

X = "ABC"

I have to use this string as an object in an object hierarchy like

a.X.b.click

For the above statement to work, X i.e. string "ABC" should be converted into an object.
How can I do this?

Upvotes: 1

Views: 6972

Answers (1)

Luc125
Luc125

Reputation: 5857

You can use a Dictionary object for your data structure.

Dim a
Dim X
X = "ABC"
Set a = CreateObject("Scripting.Dictionary")
a.Add("ABC", b)    ' Attaches the value b to the key "ABC" of the object a.

Now you can access b with eithera.Item("ABC") or a.Item(X)

The Dictionary object on MSDN: http://msdn.microsoft.com/en-us/library/aa242687

Upvotes: 2

Related Questions