结构体如下
Public Type BasalInfo
    name As String          '设备名
    IP As String            '设备IP
    MACAddress As String    'MAC地址
    SubNet As String        '子网掩码
    gateway As String       '网关
    UserID As String        '用户名
    pwd As String           '密码
    type As String          '设备类型
    AppSys As String        '应用系统
End Type在class module中我是这么用的
Public Function SetBaseInfo(strIPAddr As String, info As BasalInfo) As Integer
……
End Function可是运行时出现错误消息框:
Compile Error:
Only public user defined types defined in public object modules can be used as parameters or return types for public procedures of class modules or as fields of public user defined types.

解决方案 »

  1.   

    '在类就不能用Public 来定义了.用privateprivate Function SetBaseInfo(strIPAddr As String, info As BasalInfo) As Integer
    ……
    End Function
      

  2.   

    VB规定,只有在公共对象模块中定义的公共用户定义类型可以作为参数、类模块的公共过程返回类型、公共用户定义类型的字段使用。因此定义在模块中的类型是不能作为参数类型的,另外,楼上 tztz520(午夜逛街)说的好象也不行的,你可以:1. 将参函数原型的参数类型定义为Variant
    2. 将用户自定义类型更换成一个类定义, 不过这好象对性能产生影响。
      

  3.   

    在ActiveX DLL或ActiveX Exe中你可以在Instancing属性为GlobalMultiUse的类模块中使用Public声明
      

  4.   

    Option Explicit'Form1
    Private Sub Form_Load()
        Dim bi As BasalInfo
        Dim cls As New Class1
        Dim s As String
        
        bi.IP = "xxx.x.x.xx"
        bi.MACAddress = "xxxxxxxxxxxxxxxxxxxxxx"
        cls.SetBaseInfo s, VarPtr(bi)
        
    End Sub'Module1
    Option ExplicitPublic Type BasalInfo
        IP As String
        MACAddress As String
    End TypePublic Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
    'Class1
    Option ExplicitPublic Function SetBaseInfo(strIPAddr As String, ByVal pInfo As Long) As Integer
        Dim bi As BasalInfo
        
        bi.IP = ""
        bi.MACAddress = ""
        CopyMemory ByVal bi, ByVal pInfo, Len(bi)
        MsgBox bi.IP
        
    End Function
      

  5.   

    谢谢 leolan(史留香) 
    方法可行!