有关VB6的类模块问题!急请高手回答!!
新建一个窗体,添加一个模块Module1,添加了3个类模块分别为Class1,Class2,Class3,Class1里面代码为Privatem_qqAsClass2Pr...
新建一个窗体,添加一个模块Module1,添加了3个类模块分别为Class1,Class2,Class3,Class1里面代码为
Private m_qq As Class2
Private m_qq1 As Integer
Public Property Get C2() As Class2
Set C2 = m_qq
End Property
Public Property Let qq(ByVal vNewValue As Class2)
Set m_qq = vNewValue
End Property
Public Property Get qq1() As Integer
qq1 = m_qq1
End Property
Public Property Let qq1(ByVal vNewValue As Integer)
m_qq1 = vNewValue
End Property
Class2的代码为:
Private m_ww As Class3
Public Property Get C3() As Class3
Set C3 = m_ww
End Property
Public Property Let ww(ByVal vNewValue As Class3)
Set m_ww = vNewValue
End Property
Class3代码
Private m_ee As Integer
Public Property Get ee() As Integer
ee = m_ee
End Property
Public Property Let ee(ByVal vNewValue As Integer)
m_ee = vNewValue
End Property
再添加个模块Module1里面的代码为
Sub main()
Form1.Show
End Sub
Public Sub gc()
Dim q As Class1
Set q = New Class1
q.qq1 = 3
Form1.Text1.Text = q.qq1
Dim o As Class3
Set o = q.C2.C3
o.ee = 4
Form1.Text2.Text = o.ee
End Sub
在窗体上添加text1和text2和一个Command1其代码为:Call gc
问 怎么提示Set o = q.C2.C3出错?求高人帮我分析一下原因,顺便问一下Set o = q.C2.C3是什么意思呢?详细点
运行后点击Command1出错 展开
Private m_qq As Class2
Private m_qq1 As Integer
Public Property Get C2() As Class2
Set C2 = m_qq
End Property
Public Property Let qq(ByVal vNewValue As Class2)
Set m_qq = vNewValue
End Property
Public Property Get qq1() As Integer
qq1 = m_qq1
End Property
Public Property Let qq1(ByVal vNewValue As Integer)
m_qq1 = vNewValue
End Property
Class2的代码为:
Private m_ww As Class3
Public Property Get C3() As Class3
Set C3 = m_ww
End Property
Public Property Let ww(ByVal vNewValue As Class3)
Set m_ww = vNewValue
End Property
Class3代码
Private m_ee As Integer
Public Property Get ee() As Integer
ee = m_ee
End Property
Public Property Let ee(ByVal vNewValue As Integer)
m_ee = vNewValue
End Property
再添加个模块Module1里面的代码为
Sub main()
Form1.Show
End Sub
Public Sub gc()
Dim q As Class1
Set q = New Class1
q.qq1 = 3
Form1.Text1.Text = q.qq1
Dim o As Class3
Set o = q.C2.C3
o.ee = 4
Form1.Text2.Text = o.ee
End Sub
在窗体上添加text1和text2和一个Command1其代码为:Call gc
问 怎么提示Set o = q.C2.C3出错?求高人帮我分析一下原因,顺便问一下Set o = q.C2.C3是什么意思呢?详细点
运行后点击Command1出错 展开
2个回答
展开全部
因为类还没有初始化。
Class1有个属性叫C2,类型是Class2;有个属性叫 qq1 ,类型是 Integer;
Class2有个属性叫C3,类型是Class3;
Class3有个属性叫ee,类型是Integer。
Set q = New Class1 这句话把 q (Class1) 初始化了,但只对 qq1 属性赋值,它的 C2 (Class2) 属性没有被初始化,里面的 C3 (Class3) 也没有被初始化,所以 Set o = q.C2.C3 就无效。
Set o = q.C2.C3 相当于把值 C3(类型:Class3)赋值给 o ,o 的类型是 Class3 ,所以它也有 ee 属性。
把Class1里的 Private m_qq As Class2 改为 Private m_qq As New Class2,
把Class2里的 Private m_ww As Class3 改为 Private m_ww As New Class3,
(加个New)
就可以正常用了。
Class1有个属性叫C2,类型是Class2;有个属性叫 qq1 ,类型是 Integer;
Class2有个属性叫C3,类型是Class3;
Class3有个属性叫ee,类型是Integer。
Set q = New Class1 这句话把 q (Class1) 初始化了,但只对 qq1 属性赋值,它的 C2 (Class2) 属性没有被初始化,里面的 C3 (Class3) 也没有被初始化,所以 Set o = q.C2.C3 就无效。
Set o = q.C2.C3 相当于把值 C3(类型:Class3)赋值给 o ,o 的类型是 Class3 ,所以它也有 ee 属性。
把Class1里的 Private m_qq As Class2 改为 Private m_qq As New Class2,
把Class2里的 Private m_ww As Class3 改为 Private m_ww As New Class3,
(加个New)
就可以正常用了。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询