Forum breadcrumbs - You are here:WeLoveGod RallysPublic Forums: futurebasicFinding decimal equivalent of 45' …
You need to log in to create posts and topics.
Finding decimal equivalent of 45'-3 1/2 etc
77,940 Posts
#1 · February 22, 2022, 2:48 pm
Quote from Forum Archives on February 22, 2022, 2:48 pmPosted 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 locallocal fn FindLength( lgth as CFStringRef) as doubleNSUinteger ft,ins,numerator, denominatorCFRange r1,r2,r3,r4,rangeCFIndex indxdouble ansr1 = 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 > -1if r1.location < 10000 // if r1.location > -1ft = fn StringIntegerValue( fn StringSubstringToIndex( lgth, r1.location))elseft = 0end ifNSLog(@"ft= %d", ft)if r2.location < 10000 and r3.location < 10000indx = r3.location - r2.locationrange = fn CFRangeMake( r2.location + 1, indx )if r3.location < 10000ins = fn StringIntegerValue( fn StringSubstringWithRange( lgth, range))end ifelseif r2.location < 10000ins = fn StringIntegerValue( fn StringSubstringFromIndex( lgth, r2.location+1))elseins = fn StringIntegerValue( fn StringSubstringToIndex( lgth, r3.location))end ifend ifNSLog(@"ins= %d", ins)if r4.location < 10000//if r3.location < 0 then r3.location = 0indx = r4.location - r3.locationrange = fn CFRangeMake( r3.location + 1, indx)numerator = fn StringIntegerValue( fn StringSubstringWithRange( lgth, range))denominator = fn StringIntegerValue( fn StringSubstringFromIndex( lgth, r4.location+1))end ifif numerator > 0 and ft > 0ans = ft + (ins + numerator/denominator)/12elseif ft > 0ans = ft + ins/12elseif numerator > 0ans = (ins + numerator/denominator)/12elseans = ins/12end ifend ifend ifelse // Special condition inches onlyans = fn StringDoubleValue(lgth)ans = ans/12end ifNSLog(@"ans= %0.4f", ans)end fn = ans'~'1fn 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 alsoHandleEventsPeter BoyleFB 7.0.11OSX 10.14.6Xcode 10.2iMac 21.5 Late 20152.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/
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/
Click for thumbs down.0Click for thumbs up.0