Lines, items, repeat loops, > not always what you think

Jim Ault JimAultWins at yahoo.com
Tue Oct 18 01:32:09 EDT 2005


Cautionary note:  I have gone to a different method of controlling repeat
loops now that I am working with database tables.

(Please note the handlers I have included below to see this 'anomaly' in
action.)

In Xtalk, the number of lines or items depends on the delimiter AND if the
last line/item has anything in it.   Due to this inconsistency, I am now
using a function ... delimCount()+1  as follows

put fld colorList into temp  --a list of 12 colors
repeat with x = 1 to delimCount(temp,return) +1
   answer  line x of temp ‹ which will now do all 12 lines, even if the last
one is empty
end repeat
 I am often looking for missing values in database tables, and if the last
column of a row, or the last line of a column is blank, it will be skipped
and my maintenance will be faulty.

Anyone have a better solution?

Jim Ault
Las Vegas

------------------ copy code and call procedure  'countAfterSort'

on countAfterSort
    --Example of the anomaly for items and lines
    --all we are doing here is sorting the same container
    --note the message box after handler completes

    put "1,7,9,4,,,,6,2,5,8,3" into temp
    put the number of items in temp & " items in > " & temp
    sort items in temp
    put  the number of items in temp & " items in > " & temp into ans
    answer "Their are " & ans
    put msg & return & ans
    sort items in temp descending numeric
    put  the number of items in temp & " items in > " & temp into ans
    answer "Their are " & ans
    put msg & return & ans
    sort items in temp ascending numeric
    put  the number of items in temp & " items in > " & temp into ans
    answer "Their are " & ans
    put msg & return & ans
    
    put "The string ALWAYS contained " & delimCount(temp,",") & \
        " commas but not always that many items" into ans
    answer ans
    put msg & return & ans
    answer "Read the message box"
    
end countAfterSort

function delimCount strr, del
    put 0 into hits
    repeat with x = 1 to number of characters in strr
        if char x of strr is del then add 1 to hits --found a delimiter
    end repeat
    return hits
end delimCount
--------------------------------------- end code



More information about the use-livecode mailing list