My goal is to parse a textual string into an array of floats... so, I have a loop and I go through the string, and... I get an error message. I will first post the line which was mentioned in the error message: On 1.3 for a FR630, programming in windows.
Failed invoking <symbol>
Unexpected Type Error
in parsePoints (C:\source\AppView.mc:165)
the offending line is this:
point_array= istr.substring(start, end).toFloat();
[/code]
in my resources I have this:
<property id="mystr" type="string">23.3456,-9.12942 12.1234,-3.2425 2.32532,-3.4352</property>
the entire function is pretty complex but essentially the string is in a "X.XXXX,Y,YYYY X.XXXX,Y.YYYY" format. Full points are separated by spaces, lat and lon pairs are separated by a comma. There can be no spaces before or after the body of the string... Pretty minimal error checking... If it doesn't work, it moves on.
I think next time I re-write that function I'll just forgo having two different delimiters... much headache. I am not a veteran loop programmer...
var point_array = new [2 * 4];
function parsePoints() {
var pointsAreGood = false;
var half = (point_array.size()/2).toNumber();
var istr = App.getApp().getProperty("mystr");
var start = 0;
var end;
for (var i = 0; i < half; i++) {
var sample = istr.substring(start, istr.length());
end = sample.find(",").toNumber();
point_array= istr.substring(start, end).toFloat(); // line 165 here: error...
if (!(point_arrayinstanceof Lang.Float)) {
Sys.println("error ingesting 1st-half");
break;
} else {
start = end;
sample = istr.substring(start, istr.length());
end = sample.find(" ").toNumber();
if (end == null) {
end = istr.length();
}
point_array[i+half] = istr.substring(start, end).toFloat();
if (!(point_array[i+half] instanceof Lang.Float)) {
Sys.println("error ingesting 2nd-half");
break;
}
start = end;
if (start == istr.length()){
pointsAreGood = true;
break;
}
}
}
if (!pointsAreGood) { // if unable to load points so try to clean up memory...
for (var i = 0; i < point_array.size(); i++) {
point_array= null;
}
}
}
[/code]
The purpose for all this is to allow the user to enter points into a lengthy string in the app settings, and have the program operate off of those settings. This seems to be the easiest way for what I want to do. If anyone has any recommendations on minimizing memory usage, such as having floats in the settings, I'd be happy to hear it. I am hoping to allow users to enter in these coordinates textually because that is not too difficult.. Thanks!