这段程序 目的是每找到一个图层就把这个图层的名字给动态数组中的一个变量,不这道怎么了 红色的部分提示有问题,谢谢指教。同时很想知道更简单的方法,谢谢
Private Sub CommandButton1_Click() Dim layerNames As String Dim entry As AcadLayer Dim layercount As Integer Dim j As Integer j = 0 layerNames = "" For Each entry In ThisDrawing.Layers layerNames = layerNames + entry.Name + vbCrLf Dim layernamesarray() As String For i = j To j layernamesarray(i) = entry.Name j = j + 1 Next Next For i = 0 To layercount - 1 MsgBox "图形中的图层有: " + vbCrLf + layernamesarray(i) Next End Sub
你的数组元素个数没有指定吧
Sub listlayer() Dim i As Integer Dim s As Integer Dim layerm() As String s = ThisDrawing.Layers.Count - 1 ReDim layerm(s) As String For i = 0 To s layerm(i) = ThisDrawing.Layers.Item(i).Name Debug.Print layerm(i) Next
End Sub