Forum Navigation
You need to log in to create posts and topics.

Finding decimal equivalent of 45'-3 1/2 etc

Posted by: paboyle1703 <paboyle1703@...>

I have the following code, which works as expected, but if I change line 16 to the red the program crashes. r1.location does not change to my way of thinking?

include "NSLog.incl"

clear local
local fn FindLength( lgth as CFStringRef) as double
NSUinteger ft,ins,numerator, denominator
CFRange r1,r2,r3,r4,range
CFIndex indx
double ans

r1 = fn StringRangeOfString( lgth, @"'")
r2 = fn StringRangeOfString( lgth, @"-")
r3 = fn StringRangeOfString( lgth, @" ")
r4 = fn StringRangeOfString( lgth, @"/")
NSLog(@"r1= %d r2= %d r3= %d r4= %d ",r1.location,r2.location,r3.location,r4.location)
if r1.location > -1 or r2.location > -1 or r3.location > -1 or r4.location > -1
if r1.location < 10000  // if r1.location > -1
ft = fn StringIntegerValue( fn StringSubstringToIndex( lgth, r1.location))
else
ft = 0
end if
NSLog(@"ft= %d", ft)
if r2.location < 10000 and r3.location < 10000
indx = r3.location - r2.location
range = fn CFRangeMake( r2.location + 1, indx )
if r3.location < 10000
ins = fn StringIntegerValue( fn StringSubstringWithRange( lgth, range))
end if
else
if r2.location < 10000
ins = fn StringIntegerValue( fn StringSubstringFromIndex( lgth, r2.location+1))
else
ins = fn StringIntegerValue( fn StringSubstringToIndex( lgth, r3.location))
end if
end if
NSLog(@"ins= %d", ins)
if r4.location < 10000
//if r3.location < 0 then r3.location = 0
indx = r4.location - r3.location
range = fn CFRangeMake( r3.location + 1, indx)
numerator = fn StringIntegerValue( fn StringSubstringWithRange( lgth, range))
denominator = fn StringIntegerValue( fn StringSubstringFromIndex( lgth, r4.location+1))
end if

if numerator > 0 and ft > 0
ans = ft + (ins + numerator/denominator)/12
else
if ft > 0
ans = ft + ins/12
else
if numerator > 0
ans = (ins + numerator/denominator)/12
else
ans = ins/12
end if
end if
end if

else // Special condition inches only
ans = fn StringDoubleValue(lgth)
ans = ans/12
end if
NSLog(@"ans= %0.4f", ans)
end fn = ans
'~'1
fn FindLength(@"45'-3 1/2")
fn FindLength(@"40'-3")
fn FindLength(@"40'-0 1/2")
fn FindLength(@"3 1/2")
//fn FindLength(@"1/4") This crashes also

HandleEvents

Peter Boyle
FB 7.0.11
OSX 10.14.6
Xcode 10.2
iMac 21.5 Late 2015 
2.8 GHz Intel Core i5

































--
To unsubscribe, send ANY message to: futurebasic-unsubscribe@freegroups.net To access the list archives, go to: http://freegroups.net/groups/futurebasic/