Code help

Code help

Anonymous
Not applicable
448 Views
1 Reply
Message 1 of 2

Code help

Anonymous
Not applicable
Morning All,

I have tried writing the below function to create a new layer. But it type
mismatches on the .TrueColor = intColourNumber line. How can I set the
colour of my layer. Also is it necessary to set variables to nothing at the
end or they will disappear automatically when the function is finished?

Public Function CreateNewLayer(ByVal strLayerName As String, intColourNumber
As Integer) As AcadLayer
Dim objAcadLayer As AcadLayer

'Create and reference the new layer
Set objAcadLayer = ThisDrawing.Layers.Add(strLayerName)

'Set layer properties
With objAcadLayer
.TrueColor = intColourNumber
End With

Set CreateNewLayer = objAcadLayer

Set objAcadLayer = Nothing
End Function
0 Likes
449 Views
1 Reply
Reply (1)
Message 2 of 2

Anonymous
Not applicable
The TrueColor property must refer to a TrueColor object.....locally declared
Variables are automatically released/cleared when the Sub/Function is
completed, unless you are using external objects such as Excel.

Public Function CreateNewLayer(ByVal strLayerName As String, intColourNumber
As Integer) As AcadLayer
Dim objAcadLayer As AcadLayer
Dim objTColor As New AcadAcCmColor

'Create and reference the new layer
Set objAcadLayer = ThisDrawing.Layers.Add(strLayerName)
objTColor.ColorIndex = intColourNumber

'Set layer properties
With objAcadLayer
.TrueColor = objTColor
End With

Set CreateNewLayer = objAcadLayer

Set objAcadLayer = Nothing
End Function

"Scott Viney" wrote in message
news:[email protected]...
Morning All,

I have tried writing the below function to create a new layer. But it type
mismatches on the .TrueColor = intColourNumber line. How can I set the
colour of my layer. Also is it necessary to set variables to nothing at the
end or they will disappear automatically when the function is finished?
0 Likes