天龙八部 发表于 2006-9-23 09:18:00

关于AUTOCAD VBA二次开发教程第87页那道题目的出错提出

<P>Public Sub CreateCircleToText()<BR>&nbsp;&nbsp;&nbsp; Dim objText As AcadText<BR>&nbsp;&nbsp;&nbsp; Dim ptPick As Variant<BR>&nbsp;&nbsp;&nbsp; ThisDrawing.Utility.GetEntity objText, ptPick, "拾取文字:"<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; ' 获得文字的包围框<BR>&nbsp;&nbsp;&nbsp; Dim ptMin As Variant, ptMax As Variant<BR>&nbsp;&nbsp;&nbsp; objText.GetBoundingBox ptMin, ptMax<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; ' 获得圆心和半径<BR>&nbsp;&nbsp;&nbsp; Dim ptCenter(0 To 2) As Double<BR>&nbsp;&nbsp;&nbsp; ptCenter(0) = (ptMin(0) + ptMax(0)) / 2<BR>&nbsp;&nbsp;&nbsp; ptCenter(1) = (ptMin(1) + ptMax(1)) / 2<BR>&nbsp;&nbsp;&nbsp; ptCenter(2) = 0<BR>&nbsp;&nbsp;&nbsp; Dim radius As Double<BR>&nbsp;&nbsp;&nbsp; radius = Sqr((ptMin(0) - ptMax(0)) ^ 2 + (ptMin(1) - ptMax(1)) ^ 2) / 2<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; ' 创建圆<BR>&nbsp;&nbsp;&nbsp; Dim objCircle As AcadCircle<BR>&nbsp;&nbsp;&nbsp; Set objCircle = ThisDrawing.ModelSpace.AddCircle(ptCenter, radius)<BR>End Sub</P>
<P>最后运行结果是弹出一个MSGBOX,提示"类型不匹配"</P>

efan2000 发表于 2006-9-23 23:43:00

objText定义为AcadText,所以选择的只能是单行文字。检查一下是不是这儿出错了。

天龙八部 发表于 2006-9-24 16:26:00

恩,说的是,昨天和你一起出书的同志已经帮我解决了问题,谢谢王老哥
页: [1]
查看完整版本: 关于AUTOCAD VBA二次开发教程第87页那道题目的出错提出