明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 592|回复: 3

为何遍历对象也会下标越界?

[复制链接]
发表于 2019-3-23 15:05 | 显示全部楼层 |阅读模式

这样也会下标越界?另外,为什么编译器只提示错误但没有了“调试”按钮?


For Each Objt In SeleObjts


If TypeOf Objt Is AcadLine Then
   nLine = nLine + 1:   ReDim Preserve Lines(1 To nLine):    Set Lines(nLine) = Objt
End If


Next Objt


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2019-5-10 11:22 | 显示全部楼层
‘以下代码经过我测试可以正常运行


Sub test()
'创建选择集
Dim seleobjts As AcadSelectionSet
Set seleobjts = ThisDrawing.SelectionSets.Add(Time)
seleobjts.SelectOnScreen

'你的代码部分
Dim nline As Integer
Dim lines() As AcadObject
Dim objt As AcadObject
For Each objt In seleobjts
If TypeOf objt Is AcadLine Then
   nline = nline + 1:   ReDim Preserve lines(1 To nline):    Set lines(nline) = objt
End If
Next objt

'检查结果
a = lines()
MsgBox UBound(a)
End Sub


发表于 2019-5-10 11:24 | 显示全部楼层
运行代码选择了3根直线,最后消息框提示数字“3”,所以应该是没问题的。可能是你的其它部分的代码有误?
 楼主| 发表于 2019-6-7 12:36 | 显示全部楼层
感谢回复,确实是其他代码有问题。因为当时设置了错误就退出,所以没有办法定位到出现异常的语句上,以为是遍历对象这里出错了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-27 08:09 , Processed in 0.576409 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表