Select to view content in your preferred language

Getting test execution error in Arcade Playground

1221
2
Jump to solution
07-09-2024 03:19 PM
Markbe_utco
Regular Contributor

I'm getting a "Test execution error":

Test execution error: Execution error - Out of bounds. Verify test data

Ultimately this script will be used to parse down a field from the attribute table so I wrote it in the ArcGIS Arcade Playground to get a better handle on how to parse the text.  Yes I know I have lots of calls to Console, this was me trying to figure out where the problem was occurring since error message was ever so helpful.

I turns out the error is being cause by what I think should be a simple variable assignment line.

When line 56 is commented out the script actually runs, albeit not the end result that I want.

On Line 55  I'm trying to assign the variable prefix a string that will be processed through the next iteration of the for loop that begins on line 31.

I still get the message even when Line 55 is commented out and I use Line 56 as a simple string.

var name = "12 45 78 01 34 6 IFD A"
var lenToIFD = Find(" IFD", name)
//var noIFDname = replace(name, " IFD","") 
var noIFDname = left(name, lenToIFD) 
var fullName = replace(name, "IFD", "\nInfrastructure\nFinancing\nDistrict")
var nameLen = count(name)
var arrayName = split(noIFDname, " ")
var maxLength = 14
var prefix = ""
var finalOutput = ""
var counter = 0
var prefixArray = []
var prefixArrayCounter = 0

Console(noIFDname)
console(prefix)

console(lenToIFD)
console(maxLength)
Console((arrayName))

Console("OOOOOOOOOOOOOOOOOOOOOO")
// determine district number from text at end of Plat Name
var distNum = right(name, nameLen - lenToIFD-4)

// Find text plat name before IFD 
if (lenToIFD <= maxLength){
  prefix = left(name,lenToIFD)
}
else{
  for (var index in arrayName){
    Console("============")
    Console(index)
    Console(counter)
    Console((prefixArrayCounter))
    Console(arrayName[index])
    if (index == counter){
      if (count(arrayName[index])<= maxLength){
        Console("Begin While Loop") 
        Console(count(prefix))      
        while (count(prefix)< maxLength){
          console(arrayName[counter])

          prefix = prefix + " " + arrayName[counter]
          counter = counter + 1
          index = counter
          Console(prefix)
        }
        Console("End While Loop")
        Console(("XXXXXXXXXXXXXXXXX"))
        console(arrayName[counter])
        prefixArray[prefixArrayCounter] = replace(prefix," ","",false)
        Console(prefixArray[prefixArrayCounter])
        var newPrefix = replace(noIFDname, prefixArray[prefixArrayCounter],"")
        prefix = newPrefix
        //prefix = "QQQ"
        Console("NewPrefix")
        Console(newPrefix)

        prefixArrayCounter = prefixArrayCounter +1
        if (index <= counter){
          Console("CONTINUE")
          continue
        }
      }
    }
    else{
      continue
    }
    var varTemp = replace(prefix," ","",false)

  }
}
console(prefixArray)
finalOutput = varTemp +"\nInfrastructure\nFinancing District" + distNum
return(finalOutput)

What am I not seeing?

Thank you

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

It's lines 44 through 46, when you assign to prefix the value

prefix + " " + arrayName[counter]

You increment the counter, then on the next loop, the counter has exceeded the length of the array, giving you the out of bounds warning.

You probably want to add some logic to catch when the counter is higher than the length of the array.

Out of curiosity, what is the expected output of this example?

- Josh Carlson
Kendall County GIS

View solution in original post

0 Kudos
2 Replies
jcarlson
MVP Esteemed Contributor

It's lines 44 through 46, when you assign to prefix the value

prefix + " " + arrayName[counter]

You increment the counter, then on the next loop, the counter has exceeded the length of the array, giving you the out of bounds warning.

You probably want to add some logic to catch when the counter is higher than the length of the array.

Out of curiosity, what is the expected output of this example?

- Josh Carlson
Kendall County GIS
0 Kudos
Markbe_utco
Regular Contributor

Thanks for responding so quickly. 

I'm using it to change the title of a map within a map series.  The expected output is the formatting of a text attribute that may contain several words into multiple lines which have a set character limit.  I have a defined amount of horizontal space but not so restricted on vertical space so I'm trying to break down the title into multiple lines.

0 Kudos