结构体如下
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.
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.
……
End Function
2. 将用户自定义类型更换成一个类定义, 不过这好象对性能产生影响。
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
方法可行!