Insert and delete Commas
Jan Schenkel
janschenkel at yahoo.com
Wed Sep 18 10:55:01 EDT 2002
Hi Bob,
During a rare "awake" moment I also rescripted your
other handler. This should handle very long numbers
better than the SuperCard functions, as well...
on insertCommaCd startNum, finishNum
--syntax: insertCommaCd --[integer, integer]
repeat with x = startNum to finishNum
put insertCommas(fld x) into fld x
end repeat
end insertCommaCd
function insertCommas pNumber
-- first strip off and save the sign
if char 1 of pNumber is "-" then
put "-" into tMinusHold
delete char 1 of pNumber
else
put "" into tMinusHold
end if
-- now strip off and save the decimal part
get offset(".", pNumber)
if it > 0 then
put char it to -1 into tDecimalHold
delete char it to -1 of pNumber
else
put "" into tDecimalHold
end if
-- now determine how many commas to place
put length(pNumber) into tLength
put (tLength DIV 3) into tCommas
if (tLength MOD 3) = 0 then subtract 1 from tCommas
-- insert the commas into the integer part
repeat with i = tCommas down to 1
put "," after char - (i * 3 + 1) of pNumber
end repeat
-- put everything back together
return tMinusHold & pNumber & tDecimalHold
end insertCommas
Hope this helped,
Jan Schenkel.
"As we grow older, we grow both wiser and more foolish
at the same time." (De Rochefoucald)
--- Robert Presender <rpresender at earthlink.net> wrote:
> The following custom handlers(?) are used in an
> application developed
> in SuperCard.
> They are used for math processes such as addition,
> subtraction, etc..
> They work in Rev.
>
> Would appreciate any comments relating to shorting
> or modifying the
> scripts or a different approach. The scripts are to
> be used on Mac and
> Windows platforms.
>
> Regards ... Bob
>
> on insertCommaCd startNum, finishNum --number must
> end in .00.
> --syntax: insertCommaCd --[integer, integer]
> repeat with x = startNum to finishNum
> if char 1 of fld x is "-" then
> put "-" into minusHold
> delete char 1 of fld x
> else
> put "" into minusHold
> end if
>
> if "," is not in fld x then
> get the number of chars of fld x
> if it >= 7 and it <= 9 then
> put "," after char (it -6) of fld x
> else
> if it >= 10 then
> get the number of chars of fld x
> put "," after char (it -9) of fld x
> put "," after char (it -5) of fld x
> end if
> end if
> end if
> put minusHold before char 1 of fld x
> end repeat
> end insertCommaCd
>
> --**Deletes commas from multiple or single fields
> having 1 or
> --**more lines per field. Minus numbers can be used
> on deleteComma startNo, finishNo --syntax:
> deleteComma [integer,
> integer]
> repeat with x = startNo to finishNo
> get the number of lines of fld x
> repeat with y = 1 to it
> if "," is in line y of fld x then --**
> get offset(",", line y of fld x )
> delete char it of line y of fld x
> if it is not 0 then
> get offset(",", line y of fld x )
> delete char it of line y of fld x
> else
> next repeat
> end if
> end if
> end repeat
> end repeat
> end deleteComma
__________________________________________________
Do you Yahoo!?
Yahoo! News - Today's headlines
http://news.yahoo.com
More information about the use-livecode
mailing list