Children shortcuts

As covered in How to access children, cJobect children are roughly equivalent to JavaScript objects’ children. However the syntax of VBA means that we have to be a little more verbose than JavaScript. To help a bit, here are some shortcuts for accessing property values.


This will return the value of the selected property

job.child("somekey").value

or, as we learned in How to access children, by childIndex

job.children(1).value

Similarly, this will convert it to to a string

job.child("somekey").toString

or by childIndex

job.children(1).toString

 

This is roughly equivalent to simply job.somekey or job[0]  and job.somekey.toString() or job[0].toString()


However you can pass the name of the child as an argument to toString() or to value() ( actually in the case of value() we have to use cValue() when passing a child name  (.. it’s a long story but it’s to do with limitations in VBA classes), so we can rewrite the .child() examples above as 


This will return the value of the selected property

job.cValue("somekey")

and

job.toString("somekey")

Grandchildren

these methods take the same arguments as .child() , so these examples all work

job.child("achild").child("agrandchild").cValue("agreatgrandchild")

is equivalent to

job.cValue("achild.agrandchild.agreatgrandchild")

which is close to the JavaScript

job.achild.agrandchild.agreatgrandchild

You can also mix index and named keys, so

job.children(1).toString("name")

 

is equivalent to

job.toString("1.name")

 

and the JavaScript equivalent

job[0].name.toString()

Now let’s look at some more cJobject topics.

For more on this see How to use cJobject