Solved

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

Posted on 2001-08-16
13
863 Views
Last Modified: 2007-12-19
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?
0
Comment
Question by:havyn
  • 7
  • 6
13 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 6393072
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))
0
 

Author Comment

by:havyn
ID: 6393114
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.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6393132
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)
0
 

Author Comment

by:havyn
ID: 6393202
Okay... I DID get it to give me a response. It's type "Variant()". What can I do with that with JScript?
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6393234
Ok, lets try something like this:

var temp = RS.Fields(0).toArray
0
 

Author Comment

by:havyn
ID: 6393338
Object doesn't support this property or method.

Same with .toString().
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 28

Expert Comment

by:AzraSound
ID: 6393388
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
0
 

Author Comment

by:havyn
ID: 6393423
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.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6393452
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];
}
0
 

Author Comment

by:havyn
ID: 6393515
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.
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 155 total points
ID: 6393559
This article looks to explain some of this, though I havent read it in great detail yet:

"PRB: Script Error Occurs When Referencing Non-variant Array"
http://support.microsoft.com/support/kb/articles/q165/9/67.asp


One thing I did see, and you should try, is to use:

Response.Write typeof(RS.Fields(0))

If you get "unknown", the returned array you are getting is not supported.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6393567
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."
0
 

Author Comment

by:havyn
ID: 6393768
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!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now