I've ran into a problem that I need some help with. I'm hoping that someone
has seen this before.
I have a field on a form which is checked "numeric", and I set the maximum
length of this field to be 9. This function seems to work fine when I'm
using the palm, but in Gremlins the error surfaces. If I comment all of the
code in this function and hardcode a return of 0.0, it fixes the error.
Now I'm guessing Gremlins is triggering this error by writing nine numbers
without a decimal, which when put through this function, will return nine+.0
This exceeds the limit set on that field.
The only thing that makes me not believe this is that an error still exists
if I check the string length to see if it's greater than 7. For testing
purposes I did this to narrow down the trouble. if(StrLen(str) > 7)
return(0.0);
Has anyone seen this before? Any help would be appreciated.
double strToDouble(CharPtr str)
{
int i, start, length, punctPos;
double result, sign, fractPart;
result = fractPart = 0.0;
length = punctPos = StrLen(str);
sign = 1.0;
start = 0;
// Determine if decimal is present.
// Because of Numeric checked in Resource,
// you don't have to worry about a ' ' at str[0]
if(str[0] == '-')
{
sign = -1.0;
start = 1;
}
// Parse the string from left to right
for(i = start; i < length; ++i)
{
// Converting the integer part
if(str[i] != '.')
if(TxtCharIsDigit(str[i]))
result = result * 10.0 + (str[i] - 0x30);
else
{
FrmAlert(NumberRangeErrorAlert);
return(0.0);
}
else
{
punctPos = i;
break;
}
}
// Parse the string from the end to the '.'
if(str[punctPos] == '.')
{
// Converting the fractional part
for(i = length - 1; i > punctPos; --i)
if(TxtCharIsDigit(str[i]))
fractPart = fractPart / 10.0 + (str[i] - 0x30);
else
{
FrmAlert(NumberRangeErrorAlert);
return(0.0);
}
result += fractPart / 10.0;
}
return(result * sign);
}
--
Tim Astle
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/