Re: Session.Contents.Remove

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: J. Baute (WUPYRDEDAWJD_at_spammotel.com)
Date: 03/19/04


Date: Fri, 19 Mar 2004 09:24:30 +0100

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" <ytNOSPAM@MAPSONfunkychickens.org> wrote in message
news:OH8EwKTDEHA.3472@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



Relevant Pages

  • RE: Error 3021
    ... Create proto-file names using the selected job names and storre to an array ... Save and close the document and repeat the loop ... Dim strJobsAs String, strDocsAs String, varValsAs _ ...
    (microsoft.public.access.modulesdaovba)
  • RE: Error 3021
    ... Kevin Backmann ... Create proto-file names using the selected job names and storre to an array ... Save and close the document and repeat the loop ... Dim strJobsAs String, strDocsAs String, varValsAs _ ...
    (microsoft.public.access.modulesdaovba)
  • RE: Error 3021
    ... Create proto-file names using the selected job names and storre to an array ... Save and close the document and repeat the loop ... Dim strJobsAs String, strDocsAs String, varValsAs _ ...
    (microsoft.public.access.modulesdaovba)
  • Re: Displaying a large amount of data quickly (VB6)
    ... >>> involving a loop of VB code would be too slow. ... but I'd sure be interested to know if that StringBuilder ... Array elements: 25000 ... Array construction: 17 ...
    (microsoft.public.vb.controls)
  • RE: Error 3021
    ... Create proto-file names using the selected job names and storre to an array ... Save and close the document and repeat the loop ... Dim strJobsAs String, strDocsAs String, varValsAs _ ...
    (microsoft.public.access.modulesdaovba)