VB 自定义类的属性时用自定义数据类型时出错

来源:百度知道 编辑:UC知道 时间:2024/06/23 02:36:35
PtColor是我在模块中定义的数据类型:
Public Type PtColor
R As Byte
G As Byte
B As Byte
End Type

我在类模块中定义属性用的一段代码:
Private mvarImgPoint As PtColor
Public Property Let ImgPoint(ByVal vData As PtColor)
mvarImgPoint = vData
End Property
Public Property Get ImgPoint() As PtColor
ImgPoint = mvarImgPoint()
End Property

上面的语句会出现错误,该如何改正?如何在定义类的属性时用自定义数据类型?
上述代码中的ImgPoint = mvarImgPoint() 一句中的括号去掉

请joform详细说明

在类中是无法定义Public的Type的,直观的方式可以用类代替Type。

'窗体中使用,假设你的类名为Class1
Private Sub Form_Load()
Dim A As New Class1

A.ImgPoint.G = 233
Debug.Print "G=" & A.ImgPoint.G & "B=" & A.ImgPoint.B
End Sub
'------------------------------------------------------------------
'你的类
Option Explicit

Dim mvarImgPoint As New PointColorClass

Public Property Set ImgPoint(ByVal vData As PointColorClass)
Set mvarImgPoint = vData
End Property

Public Property Get ImgPoint() As PointColorClass
Set ImgPoint = mvarImgPoint
End Property

'--------------------------------------------------------------

'类PointColorClass
Option Explicit

Private Type PointColor
R As Byte
G As Byte
B As Byte
End Type

Dim myPointColor As PointColor

Public Property Let B(ByVal bB As Byte)