Link to home
Start Free TrialLog in
Avatar of havyn
havyn

asked on

"Variant" arrays? (JScript v. VBScript, LDAP, ADSI, ASP)

Okay... I'm using ADSI to access an LDAP server using JScript, but I can't actually access any of the data in the returned ResultSet because it is all of type "adVariant" (as defined in adojavas.inc). Using IsArray in VBScript returns true, and I can use it as an array with the correct results there, but I'd like to be able to access it with JScript.

I tried the built-in "VBArray" object - e.g.

var temp=new VBArray(RS.Fields(0));

but it didn't work - it gave me the error "VBArray expected".
Please help?
Avatar of AzraSound
AzraSound
Flag of United States of America image

The value held by RS.Fields(0) is an array?  Have you tried simply using the default Array object?  e.g.,

var temp = new Array();
temp = RS.Fields(0);    //not sure if you can do a direct assignment

If you cant, maybe you can loop through the array and set the values explicitly.  out of curiosity, what do you get when you do (in VBScript):

MsgBox TypeName(RS.Fields(0))
Avatar of havyn
havyn

ASKER

I've tried the default Array object - doesn't work. It gives me a zero-length array every time.

And the MsgBox TypeName(RS.FIelds(0)) line wouldn't compile -- for some reason, my server (Win2000) doesn't support the "TypeName" function.
It doesnt depend on your server, but your scripting engine.  I would imagine you have the most up to date version (at least to use TypeName).  If this is an ASP page, the problem is the MsgBox function.  You can change that to a Response.Write for display purposes.  Or, maybe you need to explicitly specify the value property of the field, e.g.,

Response.Write TypeName(RS.Fields(0).Value)
Avatar of havyn

ASKER

Okay... I DID get it to give me a response. It's type "Variant()". What can I do with that with JScript?
Ok, lets try something like this:

var temp = RS.Fields(0).toArray
Avatar of havyn

ASKER

Object doesn't support this property or method.

Same with .toString().
hmm...well, we're just getting back a plain vanilla array then.  Can you loop through that array and just write out its values, e.g.,


Dim a
a = RS.Fields(0).Value

For i = 0 To UBound(a)
   Response.Write a(i)
Next
Avatar of havyn

ASKER

Yes, I can do it with VBScript. I'm trying to do it with JScript though - all of my company's pages are written with JScript, and frankly I find JScript much less infuriating.
ok, can you do the same with a plain JScript variable?


var a;
var i;

a = RS.Fields(0).Value;
for (i=0; i<a.length; i++) {
   Response.Write a[i];
}
Avatar of havyn

ASKER

No - it has the same effects as an empty array. I tried going between a[0] and a[10], and I tried going from a[0] to a.length. No output.
ASKER CERTIFIED SOLUTION
Avatar of AzraSound
AzraSound
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Excerpt from article:

"The JSCRIPT active scripting engine does not provide support for testing the bounds or indexing SAFEARRAYs of any type including VARIANTs. However, JSCRIPT is capable of passing SAFEARRAYs from one automation object to another."
Avatar of havyn

ASKER

Well, your comments didn't exactly give me a solution, but, well, it's as close to an answer as I am going to get it seems (it turned out to be "unknown").  Thanks for all your help!