Select to view content in your preferred language

how to round labels

11237
10
10-09-2017 09:30 AM
STEVEHIRSCH
New Contributor

I have three fields that I am trying to label and one that I am trying to round to the nearest whole number.  Here is what I have so far:

"Pipe ID: " + [ID_PIPE] & vbNewLine & [DIAM_INCH] + " in." & vbNewLine & Round ( [LENGTH_FT] ) + " ft."

I keep getting an error that says:

Error 1 on line 2.

Type mismatch: 'esri_2'.

I'm pretty sure it is related to the Round ( [LENGTH_FT] ) but I don't know what I'm doing wrong...

Thanks!

0 Kudos
10 Replies
DanPatterson_Retired
MVP Emeritus

a type mismatch suggests that your Length_feet is a string and not an integer.  Check to see if it is and cast it to a float before rounding

XanderBakker
Esri Esteemed Contributor

You shouldn't be using the "+" in VBA to combine text, only use "&" for this. Also I am not sure if you have to specify the number of decimals when rounding a value. Try this: 

"Pipe ID: " & [ID_PIPE] & vbNewLine & [DIAM_INCH] & " in." & vbNewLine & Round([LENGTH_FT], 0) & " ft."‍
TedKowal
Honored Contributor

Alternatively:

"Pipe ID: " & [ID_PIPE] & vbNewLine & [DIAM_INCH] & " in." & vbNewLine & CInt([LENGTH_FT]) & " ft."

I believe if using the field calculator it only accepts Vbscript which is not as rich in functions as VBA or VB ...  The CInt will perform the .5 or higher rounding automatically.

XanderBakker
Esri Esteemed Contributor

True Ted Kowal  it is VBScript and not VBA. However, Round Function  is supported and should be used if you want for instance a single decimal.  In ArcMap you can use Python, VBScript and JScript

In ArcGIS Pro you would probably want to use ArcGIS Arcade | ArcGIS for Developers , since that seems to be the future:

"Pipe ID: " + $feature.ID_PIPE + "\n" + $feature.DIAM_INCH + " in." + "\n" + Round($feature.LENGTH_FT, 0) + " ft."
DanPatterson_Retired
MVP Emeritus

Grief... I hope not

0 Kudos
TedKowal
Honored Contributor

I am an old time VB'r   Round function was not initially part of vbscript  got added later on!  I am a dinosaur too and have used the CINT function for quick rounding for many years    In any event... I am pretty much switched over script wise to python now; application wise I am still using vb.net or until they take that away too!

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Ted Kowal , I think it is a good thing that you switched to Python for scripting.I did that a number of years ago and I'm glad I did.

Using VB.Net and ArcObjects is something which is not too future proof. It might be time to switch over to Pro and explore the possibilities. There is a webinar tomorrow that might be interesting (Building ArcGIS Pro Add-Ins and Solution Configurations):

https://www.esri.com/training/catalog/59b1d6e447f0252a6fc5a48c/building-arcgis-pro-add-ins-and-solut... 

TedKowal
Honored Contributor

I have yet to make Pro work for me... I spend more time trying to figure out why it crashes on me!  So atm I have put it aside till there is more stability.  I will keep your thoughts in mind and look at the webinar.  Thanks

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi  Dan Patterson , actually it is the way is going and although in some cases it might require some adaption, there are some nice things it offers.   See below a document I published this week with some examples:

Create pop-ups in ArcGIS Online with conditional images using Arcade 

And in version 10.6, ArcGIS Pro 2.1, there will be something new called Attribute Rules which is based on Arcade too (initially designed as functionality for the ArcGIS Utility Network Management Extension, but it will be a feature available throughout the platform).