快被气晕了,这么两行代码有毛病么?
<p>一个判断已知圆是否与两条已知线同时相交的,</p><p> dim Keym as Boolean</p><p> If ThisDrawing.ActiveSpace = acModelSpace Then<br/> Set acCircle = ThisDrawing.ModelSpace.AddCircle(Pnt1, rad)<br/> Else<br/> Set acCircle = ThisDrawing.PaperSpace.AddCircle(Pnt1, rad)<br/> End If<br/> tmpPnt = acCircle.IntersectWith(AcLine1, acExtendNone)<br/> If <font color="#ff3300">VarType(tmpPnt) <> vbEmpty</font> Then<br/> tmpPnt = acCircle.IntersectWith(AcLine2, acExtendNone)<br/> If <font color="#ff0000">VarType(tmpPnt) <> vbEmpty</font> Then Keym = True<br/> End If</p><p>Pnt1, rad已知的数,AcLine1,AcLine2是屏幕选择的,并且生成了个如下图的圆acCircle ,</p><p> </p><p>怎么执行结果就是Keym就等于True?acLine1并不与acCircle 相交啊!</p><p>我把VarType(tmpPnt) <> vbNull And VarType(tmpPnt) <> vbError 都加上了还是不行,不知道怎么写了。</p> <p>判断交点的元素数量为0试试</p> <p style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman"></font></p><p style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">我以前发了个关于 "关于求直线垂足方法的讨论" 的帖子<p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><b><span style="FONT-SIZE: 6pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: Tahoma; mso-hansi-font-family: Tahoma; mso-bidi-font-family: Tahoma;"></b><p>其中有一段是关于找交点的,以下是其中的一段代码.</p></p></font></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><b></b><p>其中有一段是关于找交点的,以下是其中的一段代码.</p></p><p style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">...</font></p><p style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">returnPnt = lineObj.IntersectWith(objline, acExtendNone)<br/> If VarType(returnPnt) <> vbEmpty Then<br/> If LBound(returnPnt) <= UBound(returnPnt) Then<br/> pt(0) = returnPnt(0)<br/> pt(1) = returnPnt(1)<br/> pt(2) = returnPnt(2)<br/> End If<br/> End If</font></p><p style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">...</font></p> <p>在你的程序中</p><p>tmpPnt = acCircle.IntersectWith(AcLine1, acExtendNone)</p><p>执行后,不管有无交点变量 <font color="#ff3300">tmpPnt </font><font color="#000000">都不再是</font><font color="#ff3300"> vbEmpty</font> 了,所以其后面的判断语句总是true.</p><p>我开始也是用 If <font color="#ff3300">VarType(tmpPnt) <> vbEmpty</font> Then 判断有无交点的,</p><p>我后来发现无交点时变量 <font color="#ff3300">tmpPnt </font><font color="#000000">的下标大于上标, 也就是 <font color="#ff3300">tmpPnt </font>是个错误的变体.</font></p><p><br/></p> <p>if ubound(<font color="#ff3300">tmpPnt</font>)>0 then</p><p>如果无交点<font color="#ff3300">tmpPnt是</font><font color="#000000">上标为-1的数组(晕,比较郁闷)</font></p> 判断很简单,ubound(<font color="#ff3300">tmpPnt</font>)>0 有交点,ubound(<font color="#ff3300">tmpPnt</font>)=-1无交点!个人经验! <p>哦,太谢谢各位了!</p><p>今天又重试了一下,用Variant变量的其中一个元素判断就好了</p><p>即 If <font color="#ff3300">VarType(tmpPnt(0)) <> vbEmpty</font> Then 就正常了。</p><p>不过看样子还是ubound(<font color="#ff3300">tmpPnt</font>)>0的方法才是正规的方法。</p><p>再次谢谢各位。</p>
页:
[1]