首先,我使用的VB6,不是VB.NET。在程序中我需要一个自定义的类型——也就是相当于C中结构,定义如下:
Type Point
X as Integer
Y as Integer
End Type
然后,我需要用这个类型定义一个类(Name是Shape)中的公共函数的参数,如下:
Public Function SetStarCenter(aPt as Point) As Integer.
问题在于:我应该把这个类型Point的声明写在哪儿? 我尝试过写在类Shape的声明区,前面冠以Public关键字(按照MSDN的说法,加不加Public是一样的),出现编译错误:Compile Error:Cannot define a Public user-defined type within a private object module
再尝试写在一个普通模块(Standard Module)的声明区,前面冠以Public关键字(按照MSDN的说法,加不加Public是一样的),又出现编译错误:Compile Error:Only public user defined types defined in public object modules can be used as parameters or return types for public procedures of class modules or as fields of public user defined types。注意:这次编译器定位出错的地方是函数上面定义公共函数SetStarCenter的地方。
那么我应该如何声明这个类型,才能够用它来定义一个公共函数的参数呢?(当然,我可以把Point声明成一个类模块,不过对如此简单的一个结构,似乎有点太大材小用了)
Type Point
X as Integer
Y as Integer
End Type
然后,我需要用这个类型定义一个类(Name是Shape)中的公共函数的参数,如下:
Public Function SetStarCenter(aPt as Point) As Integer.
问题在于:我应该把这个类型Point的声明写在哪儿? 我尝试过写在类Shape的声明区,前面冠以Public关键字(按照MSDN的说法,加不加Public是一样的),出现编译错误:Compile Error:Cannot define a Public user-defined type within a private object module
再尝试写在一个普通模块(Standard Module)的声明区,前面冠以Public关键字(按照MSDN的说法,加不加Public是一样的),又出现编译错误:Compile Error:Only public user defined types defined in public object modules can be used as parameters or return types for public procedures of class modules or as fields of public user defined types。注意:这次编译器定位出错的地方是函数上面定义公共函数SetStarCenter的地方。
那么我应该如何声明这个类型,才能够用它来定义一个公共函数的参数呢?(当然,我可以把Point声明成一个类模块,不过对如此简单的一个结构,似乎有点太大材小用了)
解决方案 »
- 求救解决ACCESS顽症:关于ACCESS多用户系统的问题
- VB6用GDI+在XP下BMP转存为JPG成功,但在WIN7下却为空白图(大小为0K)
- 关于VB如何释放控件中引用的资源~~请教达人和众路神仙
- 急招VB developer~~~~~~~!!!
- 能得高分的问题
- 请问msgbox的用法!
- 怎么样控制局域网上的电脑只能上某些网站呢!
- Wise Installation System打包出问题
- 请帮忙提取文本框中部分数据!
- 关于在textbox的KeyPress事件中用回车键模拟TAB键的问题
- copymemory怎么是倒着连接字符串的,我晕哟,哪位达人能帮忙看一下
- 数据库连接错误??在线!
Option Explicit Type Point
X As Integer
Y As Integer
End Type
Public Sub setValue(mm As Point)
MsgBox "X的值为:" & mm.X & ",Y的值为:" & mm.Y
End Sub
窗体代码:
Option ExplicitPrivate Sub Form_Load()
Dim a As Point
a.X = 6
a.Y = 7
setValue a
End Sub
Private Sub Test()
Dim pt as Point
Dim clsShape As Shape
Set clsShape = New Shape
clsShape.SetStarCenter Varptr(pt)
Msgbox "x=" & Cstr(pt.x) & vblf & "y=" & Cstr(pt.y)
End Sub'in module
Public Type Point
X as Integer
Y as Integer
End Type
Public Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)'in class
'傳遞自定義類型變量的內存地址
Public Function SetStarCenter(Byval lpPt as Long) As Integer
Dim pt As Point
pt.x = 100
pt.y = 200
CopyMemory Byval lpPt, Byval Varptr(pt), Len(pt)
End Function