我在一个Module中定义了几个自定义的数据类型。想定义一个过程,过程包括两个参数,一个是integer类型的,另一个是Variant类型的。现在想在一个Button的处理程序中定义一个自定义类型的变量,然后调用这个过程,参数为用户自定义类型的变量。但是在编译时出现如下错误:only user-defined types defined in public object modules can be coerced to or from a variant or passed to late-bound functions.
 程序大致如此:
 type MyStr
 x as integer
 y as string
 z as integer
 end type 
------------------------------------------------------
 Public sub Example(itype as integer,a as variant)
 if itype=1 then 
 call Exec2(a) 
 end sub 
------------------------------------------------------
 public sub Exec2(mystr as MyStr)
 MsgBox Mystr.y
 end sub 
-------------------------------------------------------
在窗体中的button事件函数
Private Sub Command14_Click()
dim mystr1 as MyStr
mystr1.x=1
mystr1.y="hello"
mystr1.z=3
Call Example(1,mystr1)
End Sub 
-----------------------------------------------------------
 请问这种函数调用可以实现吗?用什么方法实现?谢谢!!!

解决方案 »

  1.   

    你另外写一个ActiveX dll组件,然后放一个类模块,代码如下
    public type MyStr
     x as integer
     y as string
     z as integer
    end type 然后编译,在你的工程里添加引用,就可以在函数间传自定义的type了
      

  2.   

    定义成全局的,即前面加public
      

  3.   

    我写了activexdll文件,也加入了引用,可是在调用call Exec2(a)  时出现了
    ByRef Argument Type Mismatch, 应该将a强制类型转换成mystr类型的,可是怎么进行强制转换呢?
     谢谢!!!!