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

Jim Ault JimAultWins at yahoo.com
Tue Oct 18 13:00:04 EDT 2005


Yes, Thomas,
> put the number of lines in temp into lineCount
> if the last char of temp  is return then add one to lineCount

.. if you are creating a list you should be aware of the style that you use
to generate it.  In more complete applications where you are relying on user
input or other data sources, the 'empty' last item is a real item that needs
to be known as 'missing' or not 'filled in' (such as a form).

One example in a stack of cards.  A inventory list is kept as "one card=one
product".  
-Sort cards by product name.
-Build a list of prices from 1 to the number of cards by putting the price
into line x of pricesCollected and all are collected
-then repeat with x = 1 to the number of lines in pricesCollected to find
any missing entries.
-If the last card has no price, 567 cards would only loop 566 times
The last card needs to be fixed, but would not be done.
Made a bit worse if you wanted to rank them the highest to lowest, sort
descending would take any empty line and make it last, and a report would
not publish the last line.

Thus, a line or item may be a real inventory entry, but be ignored in
certain circumstances.  Also a danger if you have a "put empty into line x"
then sort, then an action repeat loop based on the number of lines.

99.99% of the time there would be no problem.
I am doing SQL database table work and searching the tables for missing and
incorrect values.  I have to avoid 'sort descending'.

> put the number of lines in temp into lineCount
> if the last char of temp  is return then add one to lineCount
> would be more efficient and give the same result as your delimCount.
The delimCount(string, delimiter) function can work with lines (cr) or any
item delimeter (/ tab comma quote ^).

Agreed that this is a well-know feature in xtalk, but those who are new and
those of us who collect data from external sources, this can be the reason
our polished-honed-superior-to-all automation delivers a hiccup. :-)

Jim Ault
Las Vegas


On 10/18/05 3:06 AM, "Thomas Fischer" <fischer at mail.sub.uni-goettingen.de>
wrote:

> Hi Jim,
> 
> 
>> 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
> 
> The number of lines or items does not count an additional empty object at the
> end: "A,B" and "A,B," both have two items.
> I would think this is rather a feature, because I don't have to take care of
> removing delimiters at the end after creating lists with
> put something & comma after myList
> 
> If you create your lists otherwise, it depends on the source. Some software
> will automatically put a line delimiter at the end of a field or text, others
> won't - but they will be consistent.
> 
> But I suppose for your purposes something like
> 
> put the number of lines in temp into lineCount
> if the last char of temp  is return then add one to lineCount
> would be more efficient and give the same result as your delimCount.
> 
>> 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
> 
> All the best
> Thomas Fischer
> (Salzburg)
> 
> _______________________________________________
> 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