Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2001-08-16
13
881 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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
 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

789 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