0

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
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Oct 19, 2015 at 6:00

1 Answer 1

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.

answered Oct 19, 2015 at 23:09

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.