Change layer color when creating in vb


I'm trying to change the color of a layer I just created and I can't.
This is how I'm creating the layer:

Dim lay As AcadLayer
Dim found As Boolean

found = False
For Each lay In dw.Layers
    If UCase(lay.Name) = UCase(lname) Then
        found = True
        Exit For
    End If
If Not found Then
    Set lay = dw.Layers.Add(lname)
    'change color here
End If

Can you help me with this? I tried with truecolor property but I have no idea how to do it.
Thank you.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try this:
If Not found Then
    Set lay = dw.Layers.Add(lname)
    With lay
    .color = acCyan 'or whatever you choose
    end With 
End If

Open in new window

Use of the Color property is not recommended. From the 2009 Developer Documentation....

"This property is obsolete and will be removed in a future version."

There's plenty of examples of setting the color using the TrueColor property in the developer documentation.
hey  melanel,
 if your are still using 2006 that code should still work.
 the documentation for 2008 has the same entry that darren mentioned and it looks like its been there for a while at least since 2006 or 2004 when they introduced truecolor. There is no telling when they will discontinue the property. I know that there are still obsolete features from older versions still there.
but thats no excuse to deliberately do something that is doomed or not recommended.  ;)
not sure what the dev documentation has in it but if it doesnt help you may want to look at this code also check this link that mey help you out:

I'll probably keep my old code untill I cant use it anymore just for grins ;)

good luck
Dim color As AcadAcCmColor
Set color = _
Call color.SetRGB(241, 162, 14)
entity.TrueColor = color

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
CAD/Architecture Software

From novice to tech pro — start learning today.