Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2001-08-16
13
Medium Priority
?
922 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
Independent Software Vendors: 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 465 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…
Suggested Courses

730 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