[求助]下面的程序总是提示有错
本帖最后由 作者 于 2004-11-25 18:43:00 编辑 <br /><br />如图所示,处理四边形没有问题,如果处理的是如图所示的六边形,总是提示出错了
Sub tt()<BR> Dim pnt<BR> Dim picked As Boolean<BR> Dim px() As Double<BR> Dim py() As Double<BR> Dim i, k, j As Integer<BR> Dim pcenter() As Double<BR> Dim insertdistance() As Double<BR> Do While 1<BR> pnt = ThisDrawing.Utility.GetPoint(, "在闭合圈内点击")<BR> ThisDrawing.SendCommand "-boundary" & vbCr & "a" & vbCr & "b" & vbCr & "e" & vbCr & vbCr & pnt(0) & "," & pnt(1) & vbCr & vbCr<BR> Set pr = ThisDrawing.ModelSpace(ThisDrawing.ModelSpace.Count - 1)<BR> Dim retCoord As Variant<BR> retCoord = pr.Coordinates<BR> k = (UBound(retCoord) + 1) / 2<BR> ReDim px(UBound(retCoord)) As Double<BR> ReDim py(UBound(retCoord)) As Double<BR> For i = 0 To UBound(retCoord) Step 2<BR> px(i / 2) = retCoord(i)<BR> py(i / 2) = retCoord(i + 1)<BR> Next i<BR> <BR> ReDim pcenter(k - 2) As Double<BR> ReDim insertdistance(k - 2) As Double<BR> For i = 0 To k - 2<BR> pcenter(0) = (px(i) + px(i + 1)) / 2<BR> pcenter(1) = (py(i) + py(i + 1)) / 2<BR> insertdistance(i) = Sqr((px(i) - px(i + 1)) * (px(i) - px(i + 1)) + (py(i) - py(i + 1)) * (py(i) - py(i + 1)))<BR> insertdistance(i) = Format(insertdistance(i), "#,##0.00;;;Nil")<BR> ThisDrawing.ModelSpace.AddText insertdistance(i), pcenter, 0.65<BR> Next i<BR> <BR> picked = True<BR> <BR>Loop<BR><BR>End Sub 问题在于ReDim pcenter(k - 2) As Double
当是6边行时,ThisDrawing.ModelSpace.AddText insertdistance(i), pcenter, 0.65
中 pcenter含5个数,而坐标为3个double数元 我个人认为:如果定义为
ReDim pcenter(1) As Double
那就没有问题了
i 增加一个值,都对pcenter(0),pcenter(1)重新赋值。
但事实上程序仍然出错的。
能帮我想个办法,解决这个问题,,要能同时解决上述两种图形的情况。谢啦 下面的程序在AutoCAD MAP 2000上通过
Sub tt()<BR> On Error GoTo Err_Control<BR> Dim pnt<BR> Dim picked As Boolean<BR> Dim px() As Double<BR> Dim py() As Double<BR> Dim i, k, j As Integer<BR> Dim pcenter() As Double<BR> Dim insertdistance() As Double<BR> Do While 1<BR> pnt = ThisDrawing.Utility.GetPoint(, "在闭合圈内点击")<BR> ThisDrawing.SendCommand "-boundary" & vbCr & "a" & vbCr & "b" & vbCr & "e" & vbCr & vbCr & pnt(0) & "," & pnt(1) & vbCr & vbCr<BR> Set pr = ThisDrawing.ModelSpace(ThisDrawing.ModelSpace.Count - 1)<BR> Dim retCoord As Variant<BR> retCoord = pr.Coordinates<BR> k = (UBound(retCoord) + 1) / 2<BR> ReDim px(UBound(retCoord)) As Double<BR> ReDim py(UBound(retCoord)) As Double<BR> For i = 0 To UBound(retCoord) Step 2<BR> px(i / 2) = retCoord(i)<BR> py(i / 2) = retCoord(i + 1)<BR> Next i<BR> <BR> ReDim pcenter(0 To 2) As Double<BR> ReDim insertdistance(k - 2) As Double<BR> For i = 0 To k - 2<BR> pcenter(0) = (px(i) + px(i + 1)) / 2<BR> pcenter(1) = (py(i) + py(i + 1)) / 2<BR> pcenter(2) = 0<BR> insertdistance(i) = Sqr((px(i) - px(i + 1)) * (px(i) - px(i + 1)) + (py(i) - py(i + 1)) * (py(i) - py(i + 1)))<BR> insertdistance(i) = Format(insertdistance(i), "#,##0.00;;;Nil")<BR> ThisDrawing.ModelSpace.AddText insertdistance(i), pcenter, 0.65<BR> Next i<BR> <BR> picked = True<BR> <BR>Loop<BR>Exit_Here:<BR> Exit Sub<BR>Err_Control:<BR> Select Case Err.Number<BR> Case -2147467259<BR> '右键单击或回车或空格<BR> Err.Clear<BR> Resume Exit_Here<BR> End Select<BR> <BR>End Sub<BR> 楼上的两位版主给我很大启发 <A name=71524><FONT color=#000066><B>yulijin608</B></FONT></A>非常感谢
我看到上面得到的px,py明显是个二维点,所以下面就将插入点也当成是二维的处理了。
奇怪的是pcenter是三维的。二维的居然不通过,很是纳闷啊。
不过问题是解决了。
谢谢
页:
[1]