coloring polygons, what goes wrong in this code?

Oct 11, 2012 at 3:11 PM

Hello dear reader
i am trying to colour a polygon-layer when its created, in this example i am reading the height of buildings and depending on its height it must get a certain colour.
the error is in dutch but says system.nullreferenceException.... and so on....
the shape sure has a column with the name height
does anyone have some simple code to colour a shape based on a certain field?
    Function AddLayer(Optional ByRef nType As Short = 0) As String
        Dim Layer As IMapLayer = myVenster.AddLayer()
            If Layer IsNot Nothing Then
                If Layer.ProjectionString Is Nothing Then
                    Layer.Projection = DefineProjection()
                End If
                Dim fs As IFeatureSet = TryCast(Layer.DataSet, IFeatureSet)
                Select Case nType
                    Case 1
                End Select
                Return fs.Name
                fs = Nothing
                Return ""
            End If
        Catch ex As Exception
            MsgBox(ex.ToString, MsgBoxStyle.Critical, "Fout in AddLayer")
            Return ""
            Layer = Nothing
        End Try
    End Function

    Private Sub SetGebouwLegend(pFs As IFeatureSet)
        Dim default1 As PolygonSymbolizer = New PolygonSymbolizer(Color.LightGray)
        Dim scheme As IPolygonScheme = New PolygonScheme(pFs, "Height")
        Dim category1 As IPolygonCategory = New PolygonCategory(Color.LightBlue, Color.DarkBlue, 1)
        Dim category2 As IPolygonCategory = New PolygonCategory(Color.Pink, Color.DarkRed, 1)

            default1.OutlineSymbolizer = New LineSymbolizer(Color.Gray, 1)
            default1.LegendText = "0 - 3 meter"
            'pLayer.Symbolizer = "default"
            category1.FilterExpression = "[Height] <= 3"
            category1.LegendText = "Laagbouw"
            category2.FilterExpression = "[Height] > 3 And [Height] <= 6"
            category2.LegendText = "Eerste verdieping"
            'pLayer.ShowLabels = True
            'pLayer.Symbology = scheme

        Catch ex As Exception
            MsgBox(ex.ToString, MsgBoxStyle.Critical, "Fout in SetGebouwLegend")
        End Try

    End Sub