首次用VB6的OOP,给对象属性赋值时报错

Oceanable 2019-02-17 05:06:58
问题描述:VB6写的一个关于“门”的类,类名是OceDoor。其中一个属性是门宽度Width,与之对应的内部变量是b0。外部过程中对门宽度赋值时报错:无效的过程调用或者参数。在Property Let 过程设置了断点,发现未进入就已经报错了,所以省略了Property Let内部的实现过程。

1)类模块OceDoor里面的定义:
Dim b0 as double
==============================================================
Public Property Get Width() As Double

Width = b0

End Property
==============================================================
Public Property Let Width(ByVal NewValue As Double)

'内部实现过程省略从略

End Property


2)外部过程进行赋值的代码:
==============================================================
Public Sub SetProperty(Objt As OceDoor, PropName As String, PropValue As String)

Select Case PropName

Case "b": Objt.Width = Val(PropValue) '执行到这里报错!!!!
Case "h": Objt.Height = Val(PropValue)
Case Else: MsgBox "赋值失败!"

End Select

End Sub

3)编译器的报错:运行时错误‘5’无效的过程调用或参数
...全文
121 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
threenewbee 2019-02-18
  • 打赏
  • 举报
回复
引用 3 楼 Oceanable 的回复:
[quote=引用 2 楼 caozhy 的回复:]
另外,你的SetProperty其实完全没有必要,CallByName 了解下


=== 收到,我明白!

另外,版主您的意思就是说,我这代码没问题么?[/quote]

你的代码怎么调用的不知道,而且height也没有写,尽管你调用了。以我写的为准吧

问题解决的话,请结贴下,谢谢。
Oceanable 2019-02-18
  • 打赏
  • 举报
回复
引用 2 楼 caozhy 的回复:
另外,你的SetProperty其实完全没有必要,CallByName 了解下
=== 收到,我明白! 另外,版主您的意思就是说,我这代码没问题么?
threenewbee 2019-02-18
  • 打赏
  • 举报
回复
另外,你的SetProperty其实完全没有必要,CallByName 了解下
threenewbee 2019-02-18
  • 打赏
  • 举报
回复


Private Sub Form_Load()
Dim o As New OceDoor
SetProperty o, "h", "123"
End Sub

Public Sub SetProperty(Objt As OceDoor, PropName As String, PropValue As String)

Select Case PropName

Case "b": Objt.Width = Val(PropValue) '执行到这里报错!!!!
Case "h": Objt.Height = Val(PropValue)
Case Else: MsgBox "赋值失败!"

End Select

End Sub



Dim b0 As Double

Public Property Get Width() As Double

Width = b0

End Property

Public Property Let Width(ByVal NewValue As Double)

'内部实现过程省略从略

End Property


Public Property Get Height() As Double

Height = b0

End Property

Public Property Let Height(ByVal NewValue As Double)

'内部实现过程省略从略

End Property

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧