<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: For next slow why? in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/for-next-slow-why/m-p/3742398#M11378</link>
    <description>I repeat again, definelayer collection once then iterate through it, eg.: Option Explicit Private Sub CommandButton1_Click() On Error Resume Next 'handle exceptions inline Dim objlayers As AcadLayers Dim objlayer As AcadLayer Set objlayers = ThisDrawing.Layers 'make the layer selected in the combobox current ThisDrawing.ActiveLayer = objlayers.Item(ComboBox1.Text) For Each objlayer In objlayers objlayer.LayerOn = False 'turn off all the layers Next objlayer Set objlayer = objlayers.Item(ComboBox1.Text) If objlayer Is Nothing Then MsgBox "layer does not exist" Exit Sub 'exit if layer not found End If objlayer.LayerOn = True 'turn on the desired layer MsgBox "Done" End Sub Private Sub UserForm_Initialize() Dim layerColl As AcadLayers Dim objlayer As AcadLayer 'fill combobox Set layerColl = ThisDrawing.Layers For Each objlayer In layerColl ComboBox1.AddItem objlayer.Name Next End Sub</description>
    <pubDate>Mon, 24 Dec 2012 22:03:23 GMT</pubDate>
    <dc:creator>Hallex</dc:creator>
    <dc:date>2012-12-24T22:03:23Z</dc:date>
    <item>
      <title>For next slow why?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/for-next-slow-why/m-p/3742050#M11377</link>
      <description>&lt;P&gt;Why is the for next so slow?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a form with combobox filled up with 40 layers. The layers are from the layermanager.&lt;/P&gt;&lt;P&gt;The form has a command button too.&lt;/P&gt;&lt;P&gt;When I run this code. It's very slow to lock all layers.&lt;/P&gt;&lt;P&gt;Is there a solution for that?&lt;/P&gt;&lt;PRE&gt;Private Sub CommandButton1_Click()
On Error Resume Next    'handle exceptions inline
Dim objlayer As AcadLayer

'make the layer selected in the combobox current
ThisDrawing.ActiveLayer = ThisDrawing.Layers.Item(ComboBox1.Text)
For Each objlayer In ThisDrawing.Layers
    objlayer.LayerOn = False    'turn off all the layers
Next objlayer
Set objlayer = ThisDrawing.Layers.Item(ComboBox1.Text)
If objlayer Is Nothing Then
    MsgBox "layer does not exist"
    Exit Sub    'exit if layer not found
End If

objlayer.LayerOn = True 'turn on the desired layer
End Sub

Private Sub UserForm_Initialize()
 Dim layerColl As AcadLayers
 Dim objlayer As AcadLayer


  'fill combobox
 Set layerColl = ThisDrawing.Layers
 For Each objlayer In layerColl
    ComboBox1.AddItem objlayer.Name
 Next
 End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;gr. Laszlo&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Dec 2012 18:28:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/for-next-slow-why/m-p/3742050#M11377</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-12-22T18:28:26Z</dc:date>
    </item>
    <item>
      <title>Re: For next slow why?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/for-next-slow-why/m-p/3742398#M11378</link>
      <description>I repeat again, definelayer collection once then iterate through it, eg.: Option Explicit Private Sub CommandButton1_Click() On Error Resume Next 'handle exceptions inline Dim objlayers As AcadLayers Dim objlayer As AcadLayer Set objlayers = ThisDrawing.Layers 'make the layer selected in the combobox current ThisDrawing.ActiveLayer = objlayers.Item(ComboBox1.Text) For Each objlayer In objlayers objlayer.LayerOn = False 'turn off all the layers Next objlayer Set objlayer = objlayers.Item(ComboBox1.Text) If objlayer Is Nothing Then MsgBox "layer does not exist" Exit Sub 'exit if layer not found End If objlayer.LayerOn = True 'turn on the desired layer MsgBox "Done" End Sub Private Sub UserForm_Initialize() Dim layerColl As AcadLayers Dim objlayer As AcadLayer 'fill combobox Set layerColl = ThisDrawing.Layers For Each objlayer In layerColl ComboBox1.AddItem objlayer.Name Next End Sub</description>
      <pubDate>Mon, 24 Dec 2012 22:03:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/for-next-slow-why/m-p/3742398#M11378</guid>
      <dc:creator>Hallex</dc:creator>
      <dc:date>2012-12-24T22:03:23Z</dc:date>
    </item>
    <item>
      <title>Re: For next slow why?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/for-next-slow-why/m-p/3742433#M11379</link>
      <description>&lt;P&gt;Thank you Hallex for patient.&lt;/P&gt;&lt;P&gt;Its still slow but maybe an other way than you mean.&lt;/P&gt;&lt;P&gt;The problem is the for...next:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;For Each objlayer In objlayers&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;objlayer.Lock = True 'lock all the layers&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;Next objlayer&lt;/EM&gt;&lt;EM&gt;.&lt;/EM&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 40 layers.&lt;/P&gt;&lt;P&gt;Maybe I have to use the sendcommand &amp;nbsp;method for that?&lt;/P&gt;&lt;P&gt;ps. I changed "turn off" in "lock = true" too&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://forums.autodesk.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;Have a nice christmas!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Option Explicit
Private Sub CommandButton1_Click()

On Error Resume Next 'handle exceptions inline
Dim objlayers As AcadLayers
Dim objlayer As AcadLayer
Set objlayers = ThisDrawing.Layers 'make the layer selected in the combobox current
ThisDrawing.ActiveLayer = objlayers.Item(ComboBox1.Text)
&lt;STRONG&gt;For Each objlayer In objlayers
objlayer.Lock = True 'lock all the layers
Next objlayer&lt;/STRONG&gt;
Set objlayer = objlayers.Item(ComboBox1.Text)
If objlayer Is Nothing Then
MsgBox "layer does not exist"
Exit Sub 'exit if layer not found
End If

objlayer.Lock = False 'unlock the desired layer MsgBox "Done"
End Sub

Private Sub UserForm_Initialize()

Dim layerColl As AcadLayers
Dim objlayer As AcadLayer
'fill combobox

Set layerColl = ThisDrawing.Layers

For Each objlayer In layerColl
ComboBox1.AddItem objlayer.Name
Next
End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Dec 2012 07:28:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/for-next-slow-why/m-p/3742433#M11379</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-12-25T07:28:08Z</dc:date>
    </item>
    <item>
      <title>Re: For next slow why?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/for-next-slow-why/m-p/3742437#M11380</link>
      <description>Hi gr. Laszlo, I tested my code on drawing with about 125 layers for the test seems it's working very fast (something like less then 0.5 second) No problem if your code with SendCommand will do your job though Happy Holydays, ~'J'~</description>
      <pubDate>Tue, 25 Dec 2012 07:51:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/for-next-slow-why/m-p/3742437#M11380</guid>
      <dc:creator>Hallex</dc:creator>
      <dc:date>2012-12-25T07:51:21Z</dc:date>
    </item>
    <item>
      <title>Re: For next slow why?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/for-next-slow-why/m-p/3743489#M11381</link>
      <description>&lt;P&gt;Are you using AutoCAD x64?&lt;/P&gt;
&lt;H3 class="entry-header"&gt;&lt;A href="http://adndevblog.typepad.com/autocad/2012/05/64-bit-vba-performance-issue.html" target="_self"&gt;64 Bit VBA Performance Issue&lt;/A&gt;&lt;/H3&gt;</description>
      <pubDate>Fri, 28 Dec 2012 10:01:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/for-next-slow-why/m-p/3743489#M11381</guid>
      <dc:creator>Alexander.Rivilis</dc:creator>
      <dc:date>2012-12-28T10:01:07Z</dc:date>
    </item>
    <item>
      <title>Re: For next slow why?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/for-next-slow-why/m-p/3743717#M11382</link>
      <description>&lt;P&gt;Yes I do.....&lt;/P&gt;&lt;P&gt;???&lt;/P&gt;</description>
      <pubDate>Fri, 28 Dec 2012 20:00:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/for-next-slow-why/m-p/3743717#M11382</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-12-28T20:00:52Z</dc:date>
    </item>
    <item>
      <title>Re: For next slow why?</title>
      <link>https://forums.autodesk.com/t5/vba-forum/for-next-slow-why/m-p/3743728#M11383</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;@Anonymous wrote:&lt;BR /&gt;
&lt;P&gt;Yes I do.....&lt;/P&gt;
&lt;P&gt;???&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN class="short_text"&gt;&lt;SPAN class="hps"&gt;Then&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;read:&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;A href="http://adndevblog.typepad.com/autocad/2012/05/64-bit-vba-performance-issue.html" target="_blank"&gt;http://adndevblog.typepad.com/autocad/2012/05/64-bit-vba-performance-issue.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Dec 2012 20:24:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/for-next-slow-why/m-p/3743728#M11383</guid>
      <dc:creator>Alexander.Rivilis</dc:creator>
      <dc:date>2012-12-28T20:24:02Z</dc:date>
    </item>
  </channel>
</rss>

