Microsoft KB Archive/224422

= PRB: Returning a UDT from a VB COM Object Brings an Error =

Article ID: 224422

Article Last Modified on 7/16/2004

-

APPLIES TO


 * Microsoft Active Server Pages 4.0
 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Internet Information Server 4.0
 * Microsoft Internet Information Services 5.0

-



This article was previously published under Q224422



SYMPTOMS
When you return a user-defined data type (UDT) from a Visual Basic COM object, you might get one of the following error messages:

Microsoft VBScript runtime error '800a01a8'

Object required

-or-

Response object error 'ASP 0106 : 80020005'

Type Mismatch

?

An unhandled data type was encountered



CAUSE
User-defined data types are not supported in the current version of Active Server Pages (ASP).



RESOLUTION
Active Server Pages does not support UDTs, but you can work around this by creating a new class to handle the data in place of the UDT and setting the instancing property to PublicNotCreateable. This will ensure that you can pass the necessary information to and from ASP, as well as ensuring that the class cannot be created outside of the DLL.



STATUS
This behavior is by design.



Steps to Reproduce Behavior
 Create a Visual Basic ActiveX DLL project called VBUDTPrj. Add class module called VBUDTObj.  Define a UDT as follows: Public Type TestUDT strName as String strDept as String End Type   Implement the following method: Public Function TestMethod As Variant Dim udtTestData As TestUDT udtTestData.strDept = "TestDept" udtTestData.strName = "TestName" TestMethod = udtTestData End Function   Create an ASP page that calls this method: <%  Dim objTest, udtData Set objTest = Server.CreateObject("VBUDTPrj.VBUDTObj") udtData = objTest.TestMethod

Response.Write( "Name = " & udtData.strName & "<BR>" ) Response.Write( "Dept = " & udtData.strDept & "<BR>" ) %>                       </li> Run the ASP page. The the following error occurs:

Microsoft VBScript runtime error '800a01a8'

Object required

</li></ol>

<div class="references_section">