Hi,
var gAccum5 = [0, 0, 0, 0, 0]b;
The formatting function formatNumber():
// -----------------------------------------------------------------------
// Write number to byte array
// Number is limited to +/-9999
// Return value is number of written digit values (0, 1,...)
// -----------------------------------------------------------------------
function formatNumber(n) {
// if n is float, round it first
var nr = Math.round(n).toNumber();
// gAccum5 index
var idx = 0;
// Sign for negative number
if (nr < 0) {
gAccum5[0] = 45; // '-'
nr = -nr;
idx = 1;
}
if (nr >= 10000) {
return 0;
}
var flag = 0;
var div = 1000;
do {
if ((nr >= div) or (div == 1) or (flag)) {
System.println("Digit: " + nr + " " + idx + " " + div + " " + flag + " " + nr / div);
gAccum5[idx] = nr / div;
idx += 1; // <------------ This is line 1200
flag = 1;
nr %= div;
}
div /= 10;
} while (div);
return idx;
}
And this is the end of simulator output (Connect IQ SDK 3.1.5):
...
AV:weather: {pr=>1028, sp=>1, ic=>7, tm=>13.980000, st=>200, hm=>58, dg=>null}
Code: 7
Digit: 14 0 10 0 1
Digit: 4 1 1 1 4
Digit: 1 0 1 0 1
Digit: 1028 0 1000 0 1
Digit: 28 1 100 1 0
Digit: 28 2 10 1 2
Digit: 8 3 1 1 8
Error: Array Out Of Bounds Error
Details: Failed invoking <symbol>
Stack:
- formatNumber() at C:\Users\mates\Documents\SDK_Manager\connectiq-sdk-win-3.0.8-2019-1-23-8f00e4f\samples\Analog\source\AnalogView.mc:1200 0x10003575
- updateWeatherFields() at C:\Users\mates\Documents\SDK_Manager\connectiq-sdk-win-3.0.8-2019-1-23-8f00e4f\samples\Analog\source\AnalogView.mc:906 0x10002756
- onUpdate() at C:\Users\mates\Documents\SDK_Manager\connectiq-sdk-win-3.0.8-2019-1-23-8f00e4f\samples\Analog\source\AnalogView.mc:653 0x10001b5b
Notes:
1. The error occurrence is random, sometimes it goes through function, sometimes not - it probably depends on the number passed as function parameter.
2. The AV:weather: line in error listing is debug println of dictionary get from the background process printed just before I call sequence of formatNumber().
3. The Code: 7 is also debug println before sequence of formatNumber() is called.
4. First call of formatNumber() is with 14 as an input parameter (source AV:weather:tm rounded to 14) -> the function prints first two lines with Digit: label.
5. The second call of formatNumber() is with 1 as an input parameter (source AV:weather:sp = 1) -> the function printlns third line with Digit: label.
6. The third call of formatNumber() is with 1028 as an input parameter (source AV:weather:pr = 1028) -> the function printlns the fourth to seventh line with Digit: label.
I really do not have any idea what is wrong, the idx is always in the gAccum5[] limits.
What does the "Details: Failed invoking <symbol>" mean?
Thanks for any help.