jamesbcox1980
asked on
VBScript Anonymous Associative Arrays? (like in Javascript)
In Javascript, I can use a key-value association (associative arrays) as an argument in a function to make creating HTML tags easier. For example,
And I can call it like this:
This way, I don't need to name each attribute of an image tag as an argument in the function. This is an oversimplified version of what I'm trying to do, and in fact it has nothing to do with HTML, but it's how I learned it in JS.
Is there a way to do something similar in VBScript? I can create an associative array in VBScript like this:
But I don't know how to create an anonymous associative array like in Javascript. I need to be able to immediately plug it in as an argument in a function, without building a named array. Any ideas?
function img(attr) {
var prop, imgTag = document.createElement('img');
for (prop in attr) {
imgTag.setAttribute(prop, attr[prop]);
}
return imgTag;
}
And I can call it like this:
myElem.appendChild(img({
src : "/images/img.jpg",
alt : "Some alt text",
class : "borderImage"
});
This way, I don't need to name each attribute of an image tag as an argument in the function. This is an oversimplified version of what I'm trying to do, and in fact it has nothing to do with HTML, but it's how I learned it in JS.
Is there a way to do something similar in VBScript? I can create an associative array in VBScript like this:
Dim myArray
myArray("property1") = "value1"
myArray("property2") = "value2"
myArray("property3") = "value3"
But I don't know how to create an anonymous associative array like in Javascript. I need to be able to immediately plug it in as an argument in a function, without building a named array. Any ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yes, you would.
Like I said, it's the closest equivalent to an associative array in VBScript. I did not say it was an exact match :)
Perhaps if you tried describing what you are actually doing I or another Expert can be more helpful.
Like I said, it's the closest equivalent to an associative array in VBScript. I did not say it was an exact match :)
Perhaps if you tried describing what you are actually doing I or another Expert can be more helpful.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a bunch. See my half of the solution with the Scripting Dictionary in use.
ASKER