Programing style

Jim Ault JimAultWins at yahoo.com
Thu Nov 16 19:12:05 CST 2006


On 11/16/06 3:37 PM, "Hershel Fisch" <hershf at rgllc.us> wrote:

> On 11/16/06 5:06 PM, "Jim Ault" <JimAultWins at yahoo.com> wrote:
> 
>> Forgot to ask about final format  ? two decimals ?
> Yes, but I don't understand your code.

<<full text is below>>
Basically you are using the Rev definition of item and line to insert commas
where you want then

[1] set the ITEMdel to "." --now item 1 of tParam is just the integer

[2] set the LINEdel to "," --in Rev we can set the
itemDel, lineDel, and wordDel to what we want.

My loop iterates by inserting a comma into 'line' one of tParam.
After adding this comma, it changes tParam, so the next loop comes around
and adds another comma 3 chars ahead of the last one.

Eventually, the comma is added to the front of the tParam, which triggers
the loop to end.  Now a "$" replaces the comma that is at the front of
tParam.

Last step is to attach the decimal part of the number, if there is one.

I used the itemDel and lineDel to show a little versatility trick that Rev
offers.  A little confusing, but valid, and it expands ones horizons in
coding.

*Note  Sometimes you will be parsing a string and think that you have to use
two different itemDel characters.  It could be in this case your could use
the lineDel character of your choice,  rather than alternating.

If you are doing path names (which are one-liners), you could do

set the itemDel to "/";   set the lineDel to "."
put item 3 of fullUnixPath into tUser
put line -1 of fullUnixPath into tExtn
if the number of lines in fullUnixPath > 2 then  extra "." somewhere
put word 1 to -1 of fullUnixPathh into fullUserPathh --trim spaces
if the number of words in fullUnixPath > 1 then there is a space somewhere
set the lineDel to cr --best not to forget this

Hope this clarifies my coding a bit.
I was not trying to do one of the more obvious solutions.

Jim Ault
Las Vegas


On 11/16/06 3:37 PM, "Hershel Fisch" <hershf at rgllc.us> wrote:

> On 11/16/06 5:06 PM, "Jim Ault" <JimAultWins at yahoo.com> wrote:
> 
>> Forgot to ask about final format  ? two decimals ?
> Yes, but I don't understand your code.
>> Add one line at the end to handle this 'if there are no decimals'
>> 
>> 
>> On 11/16/06 2:00 PM, "Jim Ault" <JimAultWins at yahoo.com> wrote:
>> 
>>> --takes advantage of Rev parsing
>>> --does not handle negative numbers
>>>> function fNumericToMoney
>>> put param(1) into tParam
>>>  set itemdel to "."
>> 
>>>   put item 1 of tParam into newNum
>>>   set the lineDel to ","
> ?
>>>   repeat until char 1 of newNum is ","
> ?
>>>     put "," before char -3 of line 1 of newNum
> ?
>>>   end repeat
>>>   put "$" into char 1 of newNum
>> if item 2 of tParam is not empty
>> then put  "." & item 2 of tParam after newNum
>>>   return newNum
>>>> end fNumericToMoney
>>> 
> 
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution





More information about the use-livecode mailing list