ag503685496 发表于 2009-8-10 22:26:00

[求助]关于vb的选择集出错的问题

<p>刚开始学vba,感觉真是寸步难行啊,又只好求助朋友们啦。</p><p>代码如下</p><blockquote dir="ltr" style="MARGIN-RIGHT: 0px;"><blockquote dir="ltr" style="MARGIN-RIGHT: 0px;"><p>Private Sub CommandButton2_Click()<br/>Dim sset As AcadSelectionSet<br/>Set sset = ThisDrawing.SelectionSets.Add("a")<br/>sset.SelectOnScreen<br/>Dim entry As AcadEntity<br/>entry = sset.Item(sset.Count + 1)<br/>MsgBox ("this is a" &amp; entry.ObjectName)<br/>End Sub</p></blockquote></blockquote><p dir="ltr">运行老发生错误,百思不得其解。错误提示见附件。</p><p dir="ltr">多谢啦。</p>

mccad 发表于 2009-8-10 22:32:00

<p>没有附件!<br/>entry = sset.Item(sset.Count + 1)<br/>这句有问题。sset.item(?)是从0开始数的。所以它的最大数应该是count-1</p>

ag503685496 发表于 2009-8-10 22:34:00

<p>不好意思,这里不能传图片吗,那只能描述啦。错误提示如下:</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong> 运行时错误'-7147467259(8004005)':</strong></p><p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 方法'add'作用于对象‘iacadselectionsets'时失败</strong></p><p>我试了.SelectByPolygon 方法,还是出错。</p>

ag503685496 发表于 2009-8-10 22:38:00

<p>这么快就有回复啦。原来我这里也错啊。不过我运行时发生的错误是上面那个,麻烦再帮忙解答一下啦</p>

mccad 发表于 2009-8-10 22:40:00

<p>那是因为图中本身已存在同名的选择集了。需要先清除掉,再增加。</p><p>可参考<a href="http://www.mjtd.com/Functions/ArticleShow.asp?ArticleID=228">http://www.mjtd.com/Functions/ArticleShow.asp?ArticleID=228</a></p>

ag503685496 发表于 2009-8-10 23:26:00

<p>我改了一下,可是程序运行到红色字体处,仍然出错。显示为:运行时错误-2147467259(80004005),方法<font color="#000000">SelectOnScreen作用于对象'iacadselectionset'时失败。</font></p><blockquote dir="ltr" style="MARGIN-RIGHT: 0px;"><p>Function CreateSelectionSet(Optional SSetName As String = "mjtd") As AcadSelectionSet<br/>&nbsp;&nbsp;&nbsp; On Error Resume Next<br/>&nbsp;&nbsp;&nbsp; ThisDrawing.SelectionSets(SSetName).Delete<br/>&nbsp;&nbsp;&nbsp; Set CreateSelectionSet = ThisDrawing.SelectionSets.Add(SSetName)<br/>End Function<br/>Private Sub CommandButton2_Click()<br/>Dim SSet As AcadSelectionSet<br/>Set SSet = CreateSelectionSet<br/><font color="#f70909">SSet.SelectOnScreen<br/></font>Dim entry As AcadEntity<br/><font color="#ee3d11">entry = SSet.Item(SSet.Count - 1)<br/></font>MsgBox ("this is a")<br/>MsgBox (entry.ObjectName)<br/>End Sub</p></blockquote>

ag503685496 发表于 2009-8-11 00:17:00

<p>我又写了段代码,还是遇到上面类似的错误。我用的是cad2002,后来在2004下运行,显示的是:运行时错误,autocad主窗口不可见;再点击帮助,提示为:AutoCAD 主窗口不可见。要打开该窗口,请将应用程序对象的可见性特性设置为 acTrue。不知怎么办啦,请求帮助</p><p><br/>Private Sub CommandButton2_Click()<br/>Dim returnObj As AcadObject<br/>Dim basePnt As Variant<br/>ThisDrawing.Utility.GetEntity returnObj, basePnt, "Select an object"<br/>End Sub<br/></p>

mccad 发表于 2009-8-11 06:46:00

<p>不好意思,看你标题是VB,下面的内容中注的是VBA程序。先得搞清楚是VB和VBA。按照你上面的写法,应该都在VBA中写的。</p><p>在VBA的程序中,如果当前显示对话框时,需要先隐藏对话框才能在屏幕上选择对象。也就是需要写上me.hide。选择完对象后,再用me.show返回对话框。</p><p></p>

ag503685496 发表于 2009-8-11 07:13:00

<p>太感谢啦</p><p>原来VB和vba有这么大的区别啊</p>
页: [1]
查看完整版本: [求助]关于vb的选择集出错的问题