Solved

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

Posted on 2001-08-16
13
906 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
[X]
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
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses
Course of the Month10 days, 23 hours left to enroll

628 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