Solved

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

Posted on 2001-08-16
13
870 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel Macro: Delete a Row if Column A and B match (in that Row) 2 72
VB error "Type mismatch" 2 49
MS Access Search and Replace Using VBA 6 57
Spell Check in VB6 13 95
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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

919 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

16 Experts available now in Live!

Get 1:1 Help Now