• 0

Need help with objects


Question

Guys, I'm really struggling with objects and would appreciate any help you guys can give me. I understand that when you instantiate an object it has its own set of properties and methods, but I'm still confused. How do you find out what those properties are? I'm mostly working with VBScript right now and to be more precise Vbscript with XML.

Example:

Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("states.xml")

Dim objChildNodes, strNode
Set objChildNodes = objXMLDoc.documentElement.childNodes<State>

For Each strNode In objChildNodes
   document.write(strNode.nodeName & "<br>")
Next

objXMLDoc is obviously an object :)

async is a property of the objXMLDoc object correct?

load is a method of objXMLDoc, correct?

The next is a triple decker and throws me:

Set objChildNodes = objXMLDoc.documentElement.childNodes<State>

objChildNodes is just a variablet? It's not an object?

What is documentElement in that line?

You get the gist at this point I imagine. If I could grasp this concept it would help tremendously. Reading about programming and actually doing it is a entirely different ballgame. Any help would be appreciated. Thanks.

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

I'm not familiar with the specifics of this particular API, but in general, when you assign an object to a variable, e.g., with Set, it places a reference (an address or pointer) in the variable, which you can use to manipulate the object in code.

The first assignment of objXMLDoc gives you a reference to the document, where the second assignment, of objChildNodes, gives you a reference to the child nodes collection of the document. This too is an object, just another class of object, in this case a collection object, which is like a list of objects. A collection object supports an iterator interface, so it can be used in a foreach statement.

Responding to your question about the "triple decker" expression, objXMLDoc.documentElement.childNodes. Each "layer" is just another property accessor. "documentElement" is a property of the original document object, and "childNodes" is a property of the object returned by documentElement. You can chain accessors arbitrarily deep, working your way down into a component object structure.

In strongly typed languages like C# and VB.NET, you can only assign an object to a variable of the same declared type, but VBScript doesn't require this, which can cause problems for you.

HTH.

Edited by kaborka
Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.