如何让类模块中的m_arrayPoints数组在其他标准模块中可见?
关于MicroStation Connect Edition VBA类模块数组跨模块访问的问题
我正在为MicroStation Connect Edition(类似AutoCAD的CAD软件)编写VBA代码实现自定义功能,代码拆分在标准模块和类模块中。类模块已实现创建矩形围栏选择区域的功能,但需要把类模块里的m_arrayPoints()数组的X、Y坐标值用到其他标准模块的函数中生成数据库查询字符串,想咨询如何实现这个数组值的跨模块调用。
以下是类模块代码:
Option Explicit Option Base 0 Private Const MODULE_NAME As String = "clsPlaceFenceRectangle" ' --------------------------------------------------------------------- ' Description: ' ' Example code shows how to create a rectangular shape element and convert it to a fence. ' In other words, it mimics the operation of MicroStation's Place Fence tool. ' ' This tool works by prompting the user for two data points. These are the opposite ' vertices of a rectangle. The remaining vertices of the rectangle are calculated. ' The tool completes when two data points have been harvested. ' ' --------------------------------------------------------------------- Implements IPrimitiveCommandEvents ' --------------------------------------------------------------------- ' Class variables ' --------------------------------------------------------------------- Private m_arrayPoints() As Point3d ' Array of points from user Private m_nPoints As Integer ' Number of points supplied Private m_oView As View Private m_bKeepShape As Boolean ' Create shape and add to model Private m_bCreateFence As Boolean ' Create fence from shape ' --------------------------------------------------------------------- Public Property Let CreateFence(ByVal create As Boolean) m_bCreateFence = create End Property ' --------------------------------------------------------------------- Public Property Let KeepShape(ByVal keep As Boolean) m_bKeepShape = keep End Property ' --------------------------------------------------------------------- Private Sub IPrimitiveCommandEvents_Cleanup() End Sub ' --------------------------------------------------------------------- ' _DataPoint stores Point3d placed by user in our array ' --------------------------------------------------------------------- Private Sub IPrimitiveCommandEvents_DataPoint(point As Point3d, _ ByVal oView As View) m_nPoints = m_nPoints + 1 Set m_oView = oView ' Save view for _Reset event ' Move the AccuDraw compass, if enabled, to this data point CommandState.AccuDrawHints.SetOrigin point Debug.Print "m_nPoints=" & CStr(m_nPoints) ReDim Preserve m_arrayPoints(0 To m_nPoints - 1) m_arrayPoints(m_nPoints - 1) = point If (1 < m_nPoints) Then ShowPrompt "Place opposite point" Else ShowPrompt "Place first point" CommandState.StartDynamics End If If (2 = m_nPoints) Then ' Two points is enough to construct a rectangle Dim vertices() As Point3d CalculateRectangleVertices vertices, m_arrayPoints(0), m_arrayPoints(1) Dim oShape As ShapeElement Set oShape = CreateShapeElement1(Nothing, vertices, msdFillModeUseActive) ' Add the shape to the active model on request If m_bKeepShape Then ActiveModelReference.AddElement oShape End If If m_bCreateFence Then CreateFenceFromShapeElement m_oView, oShape End If m_nPoints = 0 End If End Sub ' --------------------------------------------------------------------- ' _Dynamics: draw shape using point array and current cursor location ' --------------------------------------------------------------------- Private Sub IPrimitiveCommandEvents_Dynamics(point As Point3d, _ ByVal oView As View, _ ByVal drawMode As MsdDrawingMode) Dim transform As Transform3d transform = Transform3dFromMatrix3dAndFixedPoint3d(Matrix3dTranspose(oView.rotation), oView.Center) If (1 = m_nPoints) Then ' Two points is enough to construct a rectangle. We already have one data point, ' and the second is provided by this _Dynamics event Dim vertices() As Point3d CalculateRectangleVertices vertices, m_arrayPoints(0), point Dim oShape As ShapeElement Set oShape = CreateShapeElement1(Nothing, vertices, msdFillModeUseActive) oShape.Redraw drawMode End If End Sub ' ------------------------------------------------------- ' CalculateRectangleVertices ' From two diagonally opposed points, calculate the remaining ' vertices of a rectangle in variable vertices. ' Vertices is allocated with five points. ' ------------------------------------------------------- Private Sub CalculateRectangleVertices( _ ByRef vertices() As Point3d, _ ByRef v1 As Point3d, _ ByRef v2 As Point3d) Const nPoints As Long = 5 ReDim vertices(0 To nPoints - 1) As Point3d Dim v As Long For v = 0 To nPoints - 1 vertices(v) = v1 Next v vertices(2) = v2 vertices(1).X = v2.X vertices(3).Y = v2.Y End Sub ' ------------------------------------------------------- Private Sub IPrimitiveCommandEvents_Keyin(ByVal Keyin As String) End Sub ' --------------------------------------------------------------------- ' Reset event not used when creating a rectangle -- 2 points is enough ' --------------------------------------------------------------------- Private Sub IPrimitiveCommandEvents_Reset() End Sub ' --------------------------------------------------------------------- ' Command starts here ' --------------------------------------------------------------------- Private Sub IPrimitiveCommandEvents_Start() ShowCommand "VBA Place Rectangular Fence Example" ShowPrompt "Place first point for rectangle" ' Clear point array and point count each time we start this command Erase m_arrayPoints m_nPoints = 0 Debug.Print "Place Rectangular Fence ..." End Sub ' ---------------------------------------------------------------------


内容的提问来源于stack exchange,提问作者Joy
相关产品推荐
相关产品推荐

