Xojo Odd data type /Out of Bounds Exception

There is a variable

pistonFunctionText(NUMPISTONFUNCTIONS) As String

that raises an OutOfBounds Exception in my Code.
Specifically,

Str(pistonFunctionText(pinFunc))

where pinFunc is an Integer.
Does either the Str command or the pistonFunctionText variable have anything that would cause an out of bounds exception?
Bug report below, with pinFunc visible.
image

Aren’t you sure pistonFunctionText is an array and the index pinFunc is out of range?

This is an array of strings, not a simple variable. The array has NUMPISTONFUNCTIONS elements.

From your debug screenshot, we can see that numpistonfunctions = 24, so the array pistonFunctionText() can hold up to 24 elements.

From your debug screenshot, we can also see you are trying to reference element number pinFunc, where that value is 99. Since that is larger than the number of elements in array pistonFunctionText() – that is 99 is greater than 24 – you get an OutOfBoundsException.

Technically, since array element are numbered from 0, when you have 24 elements they are number 0 to 23. So accessing element 99 is higher than 23. If you tried accessing element index 24 it would also be out of bounds.

I have no idea what you are trying to do or why pinFunc is 99 but NUMPISTONFUNCTIONS is 24. But that is the crux of your problem.

2 Likes

Actually, the screen shot does not show the value of numpistonfunctions, it shows the value of numpistons. It also doesn’t show pistonFunctionText(), so we really can’t tell much.

2 Likes

It’s kind of strange (and most likely problematic) that you’re calling Str() on a string.

Mea culpa. That’s what I get for trying to shoot off a quick reply. :frowning: Somehow they looked like the same name. Thanks for the correction.

Though I still think with pinFunc = 99 and an OutOfBounds exception, the pinstonFunctionText() array must have fewer elements than that.

Thank you for your responses. Yes indeed the pistonFunctionText is an Array and is created as size 15, hence the Out of Bounds Exception since pinFunc is assigned to 99 in the same method.

For the record I did not write this code, just inherited it :slight_smile: