常数、固定长度字符串、数组、用户定义类型以及declare语句不允许作为对象模块的public成员

wxl565 2011-02-18 04:20:34
第一个类模块classPoint,定义了两个变量
Option Explicit
Public X As Single
Public Y As Single
第二个类模块classData,想定义个数组。
Option Explicit
Public datas() As New pointpic

我的想法是以后用第二个类的对象来针对每个点的XY操作,如 dim a as new classData;a.datas(1).x=10 ;a.datas(1).Y=20 ;

但提示classData类定义错误:常数、固定长度字符串、数组、用户定义类型以及declare语句不允许作为对象模块的public成员

该如何实现?请教各位

...全文
1569 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
wxl565 2011-02-22
  • 打赏
  • 举报
回复
的确不行,在别的函数调用的时候会出现 对象变量或with块变量错误
wxl565 2011-02-22
  • 打赏
  • 举报
回复
Private picpars() As New pointPic


Friend Property Let datas(ByRef new_arr() As pointPic)
picpars = new_arr
End Property

Public Property Get datas() As pointPic
datas = picpars
End Property



我是这么写的 不行啊似乎
wxl565 2011-02-22
  • 打赏
  • 举报
回复
[code=V]Private datas() As New Class1

Public Function Set_Data(ByRef new_arr() As Class1)

End Function
Public Function Get_Data() As Class1()

End Function[/code]参照这个改一下应该没问题。
-----------------------------------------------------
函数中间不用写任何代码?
王二.麻子 2011-02-21
  • 打赏
  • 举报
回复
干嘛非和系统较劲那。。。不让你定义你就换地方玩呀,VB的地盘,ms做主
神马都能聊 2011-02-18
  • 打赏
  • 举报
回复
 Private datas() As New Class1

Public Function Set_Data(ByRef new_arr() As Class1)

End Function
Public Function Get_Data() As Class1()

End Function
参照这个改一下应该没问题。
wxl565 2011-02-18
  • 打赏
  • 举报
回复
我只是觉得实例化类的数组,会不会占用资源多些
wxl565 2011-02-18
  • 打赏
  • 举报
回复
好吧 同意楼上的。。男人何必为难自己
andy95800 2011-02-18
  • 打赏
  • 举报
回复
我觉得还是把Public datas() As New pointpic 放在模块里更省事一点 没必要难为自己
wxl565 2011-02-18
  • 打赏
  • 举报
回复
有具体代码例子么。。。
andy95800 2011-02-18
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 aisac 的回复:]
类内定义私有数组,然后通过属性实现。
[/Quote]


无·法 2011-02-18
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 andy95800 的回复:]

Public Property Get MyProperty() As Variant
MyProperty = MyPropValue
End Property

Public Property Let MyProperty(ByVal vNewValue As Variant)
MyPropValue = vN……
[/Quote]这个之前我也尝试了,失败告终。
神马都能聊 2011-02-18
  • 打赏
  • 举报
回复
类内定义私有数组,然后通过属性实现。
andy95800 2011-02-18
  • 打赏
  • 举报
回复
Public Property Get MyProperty() As Variant
MyProperty = MyPropValue
End Property

Public Property Let MyProperty(ByVal vNewValue As Variant)
MyPropValue = vNewValue
End Property
应该可以在类模块中构造自己的属性来代替那个数组
无·法 2011-02-18
  • 打赏
  • 举报
回复
发现确实不行,想将point改造成type xxx自定义声明还是失败了,挪到标准模块也不行,貌似没有办法了?

7,785

社区成员

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

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