You are here: > ESRI Forums > arcgis desktop discussion forums > Thread Replies

ArcGIS Desktop Discussion Forums

ArcGIS Desktop - ArcObjects General forum

Label Expression Question   Calvin Smith Nov 23, 2004
Re: Label Expression Question   Tim Whiteaker Nov 23, 2004
Re: Label Expression Question   Calvin Smith Nov 23, 2004
Re: Label Expression Question   Tim Whiteaker Nov 23, 2004
Re: Label Expression Question   Calvin Smith Nov 23, 2004
Re: Label Expression Question   Tim Whiteaker Nov 23, 2004
Re: Label Expression Question   Calvin Smith Nov 23, 2004
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Label Expression Question 
Author Calvin Smith 
Date Nov 23, 2004 
Message I would like to label a set of polygons based on their SHAPE_area. I have tried using the int([SHAPE_area) in ArcMap and it works great but when I bring it over to a mapcontrol in ArcObjects, I am getting a 'Type mismatch' error. Has anyone seen this?

Thanks! 
 
Dim pGeoLayer As IGeoFeatureLayer
    Set pGeoLayer = MapControl1.Layer(0)
    Dim pLabelEngine As ILabelEngineLayerProperties
    pGeoLayer.AnnotationProperties.Clear
    Set pLabelEngine = New LabelEngineLayerProperties
    
    Dim sRoomArea As String
    
    sRoomArea = "[" & "SHAPE_area" & "]"

    Dim sLabel As Integer
    sLabel = Int(sRoomArea)
    'MsgBox sLabel
    
    'pLabelEngine.Expression = sRoomArea
    pLabelEngine.Expression = sLabel
    pLabelEngine.IsExpressionSimple = True
    Dim pBOLayerProps As IBasicOverposterLayerProperties
    Set pBOLayerProps = New BasicOverposterLayerProperties
    pBOLayerProps.NumLabelsOption = esriOneLabelPerShape
    Set pLabelEngine.BasicOverposterLayerProperties = pBOLayerProps
    pGeoLayer.AnnotationProperties.Add pLabelEngine
    pGeoLayer.DisplayAnnotation = True
    MapControl1.ActiveView.PartialRefresh esriViewGraphics, Nothing, Nothing
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Label Expression Question 
Author Tim Whiteaker 
Date Nov 23, 2004 
Message The type mismatch is probably because pLabelEngine.Expression is expecting a String, and you are feeding it an Integer.

Instead of declaring sLabel as an Integer, declare it as a string and use the expression below. 
 
Dim sLabel As String
sLabel = "int([" & "SHAPE_area" & "])"
 
  Tim Whiteaker
Research Associate
The University of Texas at Austin 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Label Expression Question 
Author Calvin Smith 
Date Nov 23, 2004 
Message When I do this, all of my values are '0'. The same command in ArcMap's label expression gives me the values I need.
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Label Expression Question 
Author Tim Whiteaker 
Date Nov 23, 2004 
Message After you run the code, open the layer properties and look at the label expression in ArcMap. Did the code produce the same expression as when you type in the expression manually? 
  Tim Whiteaker
Research Associate
The University of Texas at Austin 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Label Expression Question 
Author Calvin Smith 
Date Nov 23, 2004 
Message Unfortunately so. I actually designed my ArcObjects expression to reflect the ArcMap expression. I am creating the code to change the labels in a standalone MapControl, so I can check the label expression afterwards.

Thanks again for your help! 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Label Expression Question 
Author Tim Whiteaker 
Date Nov 23, 2004 
Message The fact that all your labels come up as zero leads me to believe that an integer is still being fed as the label expression. For example, if the expression read

int(myfield)

then all labels would be zero, because "myfield" would be assumed to be a new variable, initialized as zero. int(0) = 0, so all labels would be zero.

The code below is working for me. If you try the code below and it still doesn't work for you, then I'm stumped.

Note that I'm testing this in ArcMap VBA, and I'm not using a MapControl (thus, the two lines involving the MapControl are different in the version I'm actually testing). 
 
Dim pGeoLayer As IGeoFeatureLayer
    Set pGeoLayer = MapControl1.Layer(0)
    Dim pLabelEngine As ILabelEngineLayerProperties
    pGeoLayer.AnnotationProperties.Clear
    Set pLabelEngine = New LabelEngineLayerProperties
    
    Dim sLabel As String
    sLabel = "int([" & "SHAPE_area" & "])"
    
    pLabelEngine.Expression = sLabel
    pLabelEngine.IsExpressionSimple = True
    Dim pBOLayerProps As IBasicOverposterLayerProperties
    Set pBOLayerProps = New BasicOverposterLayerProperties
    pBOLayerProps.NumLabelsOption = esriOneLabelPerShape
    Set pLabelEngine.BasicOverposterLayerProperties = pBOLayerProps
    pGeoLayer.AnnotationProperties.Add pLabelEngine
    pGeoLayer.DisplayAnnotation = True
    MapControl1.ActiveView.PartialRefresh esriViewGraphics, Nothing, Nothing
 
  Tim Whiteaker
Research Associate
The University of Texas at Austin 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Label Expression Question 
Author Calvin Smith 
Date Nov 23, 2004 
Message That worked for me. My apotrophies and ')' were out of place. I double checked the syntax and it's working perfectly. Thanks for all the help on that.