Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


ItemInsert() and the Lists Problem

Keywords:   itemInsert() list problem null entry

Question:

I'm having a problem with iteminsert() and I think empty strings are not handled correctly if the 1st item to insert is an empty one
k= "1"
k= iteminsert( "2",-1, k, @tab )
k= iteminsert( "3",-1, k, @tab )
results in k=1@TAB2@TAB3
which is correct

but 
k= ""
k= iteminsert( "",-1, k, @tab )
k= iteminsert( "3",-1, k, @tab )
f=itemcount( k, @tab )
results in k=3 and f= 1
which is not in my opinion
This should result in
k=@tab3 and f= 2


k= ""
k= iteminsert( "2",-1, k, @tab )
k= iteminsert( "",-1, k, @tab )
f=itemcount( k, @tab )
results in 
k=2@tab and f= 2 which is correct again
changing -1 in 0 in the 2nd line makes no difference 
so it's never possible to append an item with this function when the 1st item is empty even though it is possible when the 1st item is not empty so the behavior of this functions is not consequent in this respect I think!

Answer:

Yes, I think so too. A logical quirk in implementation. If the targetlist is empty, you cannot successfully add an empty item. There is a methodic collision in logic about an empty list and an empty item.

To avoid this problem I often initialize an empty list with an anchor item (which can be the delimiter in fact) to have at least one item in list, so appending would be ok and ItemCount can count successfully.


Article ID:   W15155