在bas模块中以下语句成立
Type nn
  n1 As Double
End Type
Function sss()
  Dim ssss As nn
  ssss.n1 = 2
  Debug.Print ssss.n1
End Function
而在cls中以下语句不成立
Function ss()
  Dim ss As nn '可以定义
  而ss--找不到ss.n1了
End Function这是为什么??????????

解决方案 »

  1.   

    这样用是可以的:
    '窗体模块:
    Option ExplicitPrivate Sub Command1_Click()
            Dim CLS As Class1
            Set CLS = New Class1
            CLS.sss
    End Sub'类模块Class1
    Option ExplicitPrivate Type nn
            n1 As Double
    End Type
    Public Function sss()
           Dim ssss As nn
           ssss.n1 = 3.1415926535
           Debug.Print ssss.n1
    End Function
      

  2.   

    定义需要private关键字,public编译后被视为属性,而且编译后的函数返回值都是一个类型,而property传值是作为参数传递的,参数的类型又要已知,所以VB的类内部不允许公有的自定义类型,职能作为私有.如果是在需要设置为公共变量,就把type end type放到模块里吧.
      

  3.   

    谢谢,楼上二位的回复.
    为什么提这个问题.目的是要将程序封装到dll文件中去.
    excel的代码封装到dll,需用VB
    chenjl1031大侠的答复,是在窗体中采用下面语句.
    Private Sub Command1_Click()
            Dim CLS As Class1
            Set CLS = New Class1
            CLS.sss
    End Sub
    而用ActiveX dll封装不需要有form马上测试和消化
    定义需要private关键字 type end type 在cls中的应用.
    再次谢谢楼上二位.
      

  4.   


    Private Type ShellType
      Mass As Double
      Volume As Double
    End Type
    放到cls中
       With shellMassAndVolume
         .Mass = 22
         .Volume = 33
       End With
    可操作,但编译成dll不成立.提示只有在公共对象模块中定义的公共用户类型可以作为参数 
    放到bas 模块中
    Public Type ShellType
      Mass As Double
      Volume As Double
    End Type
    错误提示如上.
    看来好像不可行.谢谢.