Global Variables in JScript

What am I doing wrong in JScript? I'm getting global variable index numbers instead of names.




Regards, AB

v(x) means "get me the variable called x, and create it if it doesn't already exist". So your loop is creating variables called 0, 1, 2, 3, etc.

The JScript version of VBScript's For Each is an Enumerator:

for (var ev = new Enumerator(DOpus.vars); !ev.atEnd(); ev.moveNext()) { DOpus.Output(ev.item().name); }

I am still confused. From the description of Vars in the help file:

"The Vars object represents a collection.."

and..

"You can enumerate the Var elements or refer to a specific one by its index or by its name."

Your example demonstrates how to enumerate (thanks for that) but I expected my code to work by indexing the collection.

Regards, AB :confused:

Directly indexing a collection works only for vectors. Are vectors collections? Kind of.. o)

Maybe that is of help or an example to you, a function to dump a vectors content recursively (supports vectors in vectors):

/////////////////////////////////////////////////////////////////////////////// function DumpVector( v, pad){ pad = pad || ""; for(var vIndex=0;vIndex<v.length;vIndex++){ try{ if (v(vIndex).count == undefined) throw "no vector"; DOpus.Output(pad+vIndex+" vector["+v(vIndex).count+"]"); DumpVector( v(vIndex), " "+pad); } catch(e){ DOpus.Output(pad+vIndex+" "+v(vIndex)); } } }

Do vectors have any relationship with vars? I'm not seeing the relevance of bringing them up.

The stuff about indexing the vars collection by number looks like a documentation error to me, unless there's something more subtle going on.

I think you are right Leo, I guess it was just too late and my brain not working good enough anymore. o)
Sorry, I didn't want to create any confusion!