I am having a problem resolving the oList object with my CreateObject("System.Collections.ArrayList")
The error I get in vbscript
"Microsoft VBScript runtime error: Object doesn't support this property or method: 'list.Add'"
Based on this tutorial I know you can use COM wrapped .Net components in vbscript; so why won't this work?
Additional information:
When I am debugging in VS08 and add a watch to list, it says Children could not be evaluated.
The watch for objNode.value has a two character string value. (Which is expected behavior)
Function ProcessXML(oXML)
STOP
xPathExemptions= "//Exemption/@ExemptCodeWord"
Dim xmlDoc : Set xmlDoc = CreateObject("MSXML2.DOMDocument.6.0")
xmlDoc.Async = False
xmlDoc.loadXML(oXML)
Dim colNodes
Set colNodes = xmlDoc.selectNodes(xPathExemptions)
Dim oList
Set oList = CreateObject("System.Collections.ArrayList")
Dim objNode
For Each objNode in colNodes
oList.Add = objNode.value
Next
'ProcessExemptions = CStr(xmlDoc.selectNodes(xPathExemptions))
End Function
If you have any comments on my vbscript; please let me know - just started learning and don't know best practices.
Change:
oList.Add = objNode.value
...to:
oList.Add objNode.value
or (thanks to the guidance from @Ansgar)
Call oList.Add(objNode.value)
Here's a demonstration:
Option Explicit
Dim oList : Set oList = CreateObject("System.Collections.ArrayList")
oList.Add "Banana"
oList.Add "Apple"
oList.Add "Orange"
oList.Add "Grapes"
oList.Add "Plum"
oList.Sort
Dim oItem
For Each oItem In oList
WScript.Echo oItem
Next
Expected Output:
Apple
Banana
Grapes
Orange
Plum
You can find more on the quirky rules of the use of parentheses with VB and VBScript in Eric Lippert's informative article.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With