Session.contents.remove problem

Posted on 2003-03-05
Medium Priority
Last Modified: 2011-10-03
Hello everybody.

I am experiencing a wierd problem with Session.contents.remove while attempting to remove several variants. Here is my code:

For Each strName in Session.Contents
     if Left(strName, 8) = "histemp_" then
     end if

I have 105 session variants starting with "histemp_", and EVERYTIME I call this function, it removes the 57 first variants, and thereafter continue the loop without doing it. If I use the Session.Contents(strName) = "", it works well, so I think that Remove is the problem...

Has anybody ever experienced this problem and found a solution ?

By the way, I am using win2K server SP3 with IIS5 and no .Net framework, and I know using a lot of Session variants is bad :)
Question by:HMax
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Author Comment

ID: 8071157
Oh and I don't want to use Session.Abandon, I just want to remove the specified session variants.

Accepted Solution

wslogue earned 200 total points
ID: 8071285
Hi HMax,

here's the problem. As you remove session variables, the list that you're cycling through is getting shorter but, at the same time, you're still moving forward through it.

When you remove an item from a collection, the list gets shorter and all following items effectively move down a place with the next item filling the space of the item that you've just removed.

It's a bit like pulling all Frank Sinatra CDs out of a big pile stacked up on your desk. The 10th one up is a Sinatra CD so you swiftly pull it out and the rest of the stack drops down. But you're then MOVING UP to the 11th one - what if the NEW 10th one up is also a Sinatra CD.

To solve this problem, you should whizz backwards though the list. Something like (forgive any bad syntax)

for i=Session.Contents.Count to 1 step -1
    if Left( Session.Contents(i), 8).....
    end if

Hope this helps.


Author Comment

ID: 8071326
This work perfectly and was very instructive. Thx a ton!

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question