fmfm 发表于 2004-4-18 16:34:00

获取图层名时遇到的问题 谢谢

这段程序 目的是每找到一个图层就把这个图层的名字给动态数组中的一个变量,不这道怎么了 红色的部分提示有问题,谢谢指教。同时很想知道更简单的方法,谢谢


Private Sub CommandButton1_Click()<BR>Dim layerNames As String<BR>Dim entry As AcadLayer<BR>Dim layercount As Integer<BR>Dim j As Integer<BR>j = 0<BR>layerNames = ""<BR>For Each entry In ThisDrawing.Layers<BR>layerNames = layerNames + entry.Name + vbCrLf<BR>Dim layernamesarray() As String<BR>For i = j To j<BR><FONT color=#ff0000>layernamesarray(i) = entry.Name</FONT><BR>j = j + 1<BR>Next<BR>Next<BR>For i = 0 To layercount - 1<BR>       MsgBox "图形中的图层有: " + vbCrLf + layernamesarray(i)<BR>Next<BR>End Sub<BR>

myfreemind 发表于 2004-4-18 16:50:00

你的数组元素个数没有指定吧


Sub listlayer()<BR>Dim i As Integer<BR>Dim s As Integer<BR>Dim layerm() As String<BR>s = ThisDrawing.Layers.Count - 1<BR>ReDim layerm(s) As String<BR>For i = 0 To s<BR>layerm(i) = ThisDrawing.Layers.Item(i).Name<BR>Debug.Print layerm(i)<BR>Next



End Sub<BR>

雪山飞狐_lzh 发表于 2004-4-18 17:07:00

太复杂了,错误又多,给你一个:Private Sub CommandButton1_Click()
Dim strLayer() As String
Dim i As Integer
ReDim strLayer(ThisDrawing.Layers.Count - 1) As String
For i = 0 To ThisDrawing.Layers.Count - 1
strLayer(i) = ThisDrawing.Layers(i).Name
MsgBox strLayer(i)
Next i
End Sub

fmfm 发表于 2004-4-18 17:16:00

谢谢两位老大,写出我那么烂的程序因为我根本没学过vba,呵~~


<A name=13120><FONT color=#000066><B>lzh741206</B></FONT></A>老大 写出这样的程序 你推荐教材吗,谢啦

雪山飞狐_lzh 发表于 2004-4-18 17:22:00

教材?我看的是帮助,没学过什么教材

fmfm 发表于 2004-4-18 21:19:00

那我也看帮助去.........

ZKSJLL 发表于 2004-4-18 22:51:00

程序确实构精简,非常巧妙!


妙不可言......

页: [1]
查看完整版本: 获取图层名时遇到的问题 谢谢