我正在尝试设置名为valvePos1_的对象的数据。它的方法叫做SetData,它有三个参数:String,Buckle对象和PostTop对象。当代码到达Buckle或PostTop对象时,我收到类型不匹配错误。
在父函数中:
Dim valvePos1_, valvePos6_, valvePos11_ As ValvePosition
Set valvePos1_ = New ValvePosition
Dim postTop1_, postTop6_, postTop11_ As PostTop
Set postTop1_ = New PostTop
Dim buckle1_, buckle6_, buckle11_ As Buckle
Set buckle1_ = New Buckle
....
Call valvePos1_.SetData(Cells(iRows, 2), buckle1_, postTop1_) 'first param is a String
在ValvePosition类
中Private iPosition As Integer 'position
Dim buckle_ As Buckle 'the Buckle
Dim postTop_ As PostTop 'the PostTop
'Sets all the data
Public Sub SetData(posi As Integer, buck As Buckle, pt As PostTop)
iPosition = posi
buckle_ = buck
postTop_ = pt
End Sub 'end SetData
答案 0 :(得分:1)
1)在为对象赋值时使用Set
关键字:
Set buckle_ = buck
Set postTop_ = pt
2)声明时
Dim postTop1_, postTop6_, postTop11_ As PostTop
仅postTop11_
声明为PostTop
类型,而postTop1_, postTop6_
为Variant
。明确地告诉他们:Dim postTop1_ As PostTop, postTop6_ As PostTop, postTop11_ As PostTop
同样适用于Dim valvePos1_, valvePos6_, valvePos11_ As ValvePosition
和
Dim buckle1_, buckle6_, buckle11_ As Buckle