Type mismatch error when accessing an array

L

leslie_tighe

Hello,


I have a method on a com+ object that is returning an array of objects.

I know the array is popluated as calls to check the ubound and lbound
show valid values. However, any calls to get the value of a cell in the

array results in a type mismatch error.


Microsoft VBScript runtime (0x800A000D)
Type mismatch
/idmTest/userTest.asp, line 30


I have pasted below some of the samples that i have tried. Each results

in the error above. Any suggestions on how I can access this object
would be helpful.


' Call to get the array and to validate that it is an array.
Set userObj = Server.CreateObject("idmVBApi.ComUser")
userGrpAry = userObj.getUserGroups(5790)
arySize = ubound(userGrpAry)


response.write "userGrpAry size = " & lbound(userGrpAry) & " - " &
arySize & "<br>"
response.write "userGrpAry type isArray = " & isArray(userGrpAry) &
"<br>"


' the following fails
dim index
for index = lbound(userGrpAry) to ubound(userGrpAry)
response.Write "type = " & isobject(userGrpAry(index))
response.write userGrpAry(index).grpName
next


Calls to isNull(userGrpAry(index)) also fail.


Regards
Leslie
 
B

Bob Barrows [MVP]

Hello,


I have a method on a com+ object that is returning an array of
objects.

It's hard to say without having first-hand access to your code. Hopefully
what's written in these articles will help:

http://support.microsoft.com/default.aspx?scid=kb;EN-US;244012
http://support.microsoft.com/default.aspx?scid=kb;EN-US;197956

Building COM Components That Take Full Advantage of Visual Basic and
Scripting
http://msdn.microsoft.com/library/techart/msdn_vbscriptcom.htm

Q218454 - HOWTO: Implement Array Arguments in Visual C++ COM Objects for
Active Server Pages
http://support.microsoft.com/default.aspx?kbid=218454

Bob Barrows
 
L

leslie_tighe

Bob,

Thanks for your help. I have pasted the code below withe some comments
to explain what I am doing. What is interesting is that I can access
the object just fine in VB.net. Its just through asp that i am
struggling.

' Com+ object code
<ComClass(ComUser.ClassId, ComUser.InterfaceId, ComUser.EventsId)> _
Public Class ComUser

#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
Public Const ClassId As String =
"DDCA1246-62B9-40C2-B9DD-926808410D9C"
Public Const InterfaceId As String =
"0175C8FD-E0F1-4FEE-A0B4-48EE6C39DDF8"
Public Const EventsId As String =
"A7C3EE87-2BDB-4697-8781-F3CB6F68A46D"
#End Region

' A creatable COM class must have a Public Sub New()
' with no parameters, otherwise, the class will not be
' registered in the COM registry and cannot be created
' via CreateObject.
Public Sub New()
MyBase.New()
End Sub

Public ComUser()

Public Function getUserGroups(ByVal userId As String) As
WSGroupValue()
Dim user As UserService
user = New UserService
Return user.getUserGroups(userId)
End Function

End Class

' asp code to call this object and related method
' this part works
Dim userObj
Dim grpVal
dim arySize

Set userObj = Server.CreateObject("idmVBApi.ComUser")
userGrpAry = userObj.getUserGroups(5790)
arySize = ubound(userGrpAry)

response.write "userGrpAry size = " & lbound(userGrpAry) & " - " &
arySize
response.write "userGrpAry type isArray = " & isArray(userGrpAry)

dim index
for index = lbound(userGrpAry) to ubound(userGrpAry)
' ***** each of these calls fails *****
response.Write "type = " & isobject(userGrpAry(index))
grpval = userGrpAry(index)
response.Write "Grp name = " & grpVal.grpName & "<br>"
next
 
B

Bob Barrows [MVP]

Bob,

Thanks for your help. I have pasted the code below withe some comments
to explain what I am doing. What is interesting is that I can access
the object just fine in VB.net. Its just through asp that i am
struggling.

That makes the articles i provided extremely relevant. Don't forget that
vbscript is a loosely-typed language, which makes communicating with a
strongly-typed language like VB.Net very tricky. Please carefully read those
articles. I'm sure at least one of them will contain the key to your
problem.
 
L

leslie_tighe

Thanks Bob.

The answer was that in needed to return an array of objects and not an
array of a type.
ie. object() vs. WSGroupValue()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top