I ran into this one myself a week or two ago. I didn't bother looking up an
official bug report about this, but this is what I think happens:
When you delete an item from the contents collection, it re-ordens itself
automatically. If you delete item 8, item 9 becomes the new item 8, item 10
becomes item 9 etc. The For Each loop however doesn't seem to be adjusting
it's "index", and as it was done with item 8, it moves on to item 9, and
thus skipping the new item 8. Every time an item is deleted, the for each
misses a few items because the collection reorderns itself.
I fixed this by splitting up the variables to delete, and the actual
deletion in 2 runs.
In the first loop I record what items are to be deleted by storing them in
an array. In the second loop I run over my array, and delete each key I
stored in there.
That way everything gets deleted in a single try, and no items are skipped.
"YT" <yt******@MAPSONfunkychickens.org> wrote in message
news:OH**************@TK2MSFTNGP09.phx.gbl...
Howdy,
Why the heck wouldn't this work:
for each item in Session.Contents
if NOT( Instr( item, "customer_" ) = 1 OR Instr( item, "user_" ) =
1 ) Then
Session.Contents( item ) = ""
Session.Contents.Remove( item )
end if
next 'item
response.redirect( "menu.asp" )
the code essentially - is supposed to - go through the session variables and
remove every one that doesn't being with "user_" or "customer_". So when i
try this out, it goes through and removes some, but not all of the session
variables in question. run the script 3 more times and then they are all
gone. So i inserted a bunch of response.write statements and found that not
ALL of the session variables were even being tested. Can anyone offer
explanations as to why?
regards,
yt