Select to view content in your preferred language

Arcade Help (VB to Arcade)

295
1
04-08-2024 02:17 PM
Round_Birds
New Contributor

I'm very much a beginner with arcade, for my job I have moved over from ArcMap to Pro using parcel data that's been used for years. After getting everything else configured, I still can't get this script to work in arcade.

I'm giving in and made an account to seek some help because this is too advanced for me to grasp using youtube videos alone.  

Here is the old VB that worked in ArcMap. 

Function FindLabel ( [Parcels.PIN], [Parcels.ORIG_AC] , [Parcels.DEED_AC] , [Parcels.CALC_AC] )
pre = CInt(mid( [Parcels.PIN] ,23,3))
suf = (mid( [Parcels.PIN] ,27,3))
oa = [Parcels.ORIG_AC]
da = [Parcels.DEED_AC]
ca = [Parcels.CALC_AC]
If suf = 00000 Then
parid = pre
Else
parid = pre & "." & suf
End If
If oa > 0 And da > 0 And ca > 0 Then
FindLabel = parid & vbNewLine & oa & " Ac" & vbNewLine & da & " Ac(d)" & vbNewLine & ca & " Ac(c)"
ElseIf oa = 0 And da > 0 And ca > 0 Then
FindLabel = parid & vbNewLine & da & " Ac(d)" & vbNewLine & ca & " Ac(c)"
ElseIf oa = 0 And da = 0 And ca >0 Then
FindLabel = parid & vbNewLine & ca & " Ac(c)"
ElseIf oa = 0 And da = 0 And ca = 0 Then
FindLabel = parid
ElseIf oa > 0 And da = 0 And ca > 0 Then
FindLabel = parid & vbNewLine & oa & " Ac" & vbNewLine & ca & " Ac(c)"
ElseIf oa > 0 And da = 0 And ca = 0 Then
FindLabel = parid & vbNewLine & oa & " Ac"
ElseIf oa = 0 And da > 0 And ca = 0 Then
FindLabel = parid & vbNewLine & da & " Ac(d)"
Else
FindLabel = parid & vbNewLine & oa & " Ac" & vbNewLine & da & " Ac(d)"
End If
End Function

Screenshot 2024-04-08 155711.png

What is in yellow is what I need to get it back to, what is in orange is what it looks like from the field data. 

For the PIN, I'm trying to only display the last 3 numbers before the decimal, if there's only one number then I'd like it to return just that number ex: '023' = '23'. As well as any numbers after the decimal if they are not 0.


For the Acres, Calculated are geometry (gis) based after changes, if the deeded ac is greater than a 2% difference we display both calculated and deeded. If it's less, we display just the deeded. Sometimes we don't have deeded so I need it to always at least display the calculated. (Ignore original acres, don't need those.)

If anyone has references to point me too, or just any help at all I'd appreciate it. I've fallen behind on work because I'm having to fix and make adjustments in pro and it's been a mess. (The databases are cluttered, I get errors to update but they've been updated. I did reach out for help and ESRI has helped me but I just can't waste more time trying to learn it this moment. They (databases) need to be cleaned... bad. I simply don't have the time, I'd really like to make parcel fabrics eventually to make my work more efficient. I'm learning on the fly every day.) 

0 Kudos
1 Reply
JesseWickizer
Esri Contributor

Here are a few things to note that may help:

  • In Arcade, the index values for Mid function is zero-based. So to get the characters before the decimal would be Mid([Parcels.PIN], 22, 3)
  • Convert a string to a number with the Number function. 
  • Mid returns a string, so the suf variable is a string so you need to check for an all-zero string, not that it equals the number zero (and 00000 is the same as 0).
  • You're only assigning the first 3 digits after the decimal to the suf variable but your label shows a PIN with 5 zeros after the decimal.

Keeping those notes in mind, the rest is syntax changes from VBScript to Arcade.

var pre = Number(Mid($feature['Parcels.PIN'], 22, 3), "#");
var suf = (Mid($feature['Parcels.PIN'], 26, 5));
var oa = $feature['Parcels.ORIG_AC'];
var da = $feature['Parcels.DEED_AC'];
var ca = $feature['Parcels.CALC_AC'];
var parid = pre + "." + suf;
If (suf == "00000") {
  parid = pre;
}

If (oa > 0 && da > 0 && ca > 0) {
  return parid + TextFormatting.NewLine + oa + " Ac" & TextFormatting.NewLine & da + " Ac(d)" + TextFormatting.NewLine + ca + " Ac(c)";
} Else If (oa == 0 && da > 0 && ca > 0) {
  return parid + TextFormatting.NewLine + da + " Ac(d)" + TextFormatting.NewLine + ca + " Ac(c)";
} Else If (oa == 0 && da == 0 && ca > 0) {
  return parid + TextFormatting.NewLine + ca + " Ac(c)";
} Else If (oa == 0 && da == 0 && ca == 0) {
  return parid;
} Else If (oa > 0 && da == 0 && ca > 0) {
  return parid + TextFormatting.NewLine + oa + " Ac" + TextFormatting.NewLine + ca + " Ac(c)";
} Else If (oa > 0 && da == 0 && ca == 0) {
  return parid + TextFormatting.NewLine + oa + " Ac";
} Else If (oa == 0 && da > 0 && ca == 0) {
  return parid + TextFormatting.NewLine + da + " Ac(d)";
} Else {
  return parid + TextFormatting.NewLine + oa + " Ac" + TextFormatting.NewLine + da + " Ac(d)";
}

 

0 Kudos