I am getting the compile error at pcolor.RGB.
I want to add a color to the line feature.
How to modify the code?
Public Sub surya()
Dim pmxdoc As IMxDocument
Dim pstylegallery As IStyleGallery
Dim pEnustylegalleryItem As IEnumStyleGalleryItem
Dim pstylegalleryItem As IStyleGalleryItem
Dim plinesymbol As ILineSymbol
Dim pcolor As IColorSymbol
Dim pmap As IMap
Dim player As ILayer
Dim pFealayer As IFeatureLayer
Dim pgeofealayer As IGeoFeatureLayer
Dim psimplerender As ISimpleRenderer
Set pmxdoc = Application.Document
Set pstylegallery = pmxdoc.StyleGallery
Set pEnustylegalleryItem = pstylegallery.Items("Line symbols", "ESRI.Style", "Dashed")
Set pstylegalleryItem = pEnustylegalleryItem.Next
Set plinesymbol = pstylegalleryItem.Item
plinesymbol.Width = 5#
plinesymbol.Color = pcolor.Color
Set psimplerender = New SimpleRenderer
Set psimplerender.Symbol = plinesymbol
Set pmap = pmxdoc.FocusMap
Set player = pmap.Layer(0)
Set pgeofealayer = player
Set pgeofealayer.Renderer = psimplerender
pmxdoc.UpdateContents
pmxdoc.ActiveView.Refresh
End Sub
1 Answer 1
pcolor shouldn't be an IColorSymbol (which doesn't have Color as a property) it should be an IColor (I prefer IRgbColor cast to IColor when needed) as ILineSymbol.Color is an IColor object. I suspect though that the problem is that pcolor isn't intialized:
Dim pcolor As IRgbColor
set pcolor = New RgbColorClass()
pcolor.Red = 255 ' make it red
' then later
plinesymbol.Color = pcolor ' IRgbColor is a CoClass that implements IColor
Whether you're using IColor, IRgbColor, IColorSymbol or other objects like IGeometry when you start with a new one you must initialize it to a new object to open up some memory and set the defaults otherwise the variable is pointing to nothing and you simply can't use it.