Wrox Programmer Forums
|
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 13th, 2006, 08:38 PM
Registered User
 
Join Date: Sep 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Deleting an Item from an Array

Hi--

I have some experience with ASP but not very much with arrays, and I'm having a perplexing problem. I have a calendar style page that contains a variable number of forms. When the form(s) is/are posted, I would like to have the current contents of the shopping cart (stored in an array) checked to see if any of the dates in the current cart match those posted. If so, I would like to delete those date items so that new items for those dates can be added later and not double up the entry for that date. These are school lunches ordered by student, so only 1 per student is possible. Here is a code snippet of what I have now...any help would be greatly appreciated!

tempItemCount= 0
nItemCount = 0
ReDim sItemNums(0)
ReDim nItemDesc(0)
ReDim nItemCost(0)
ReDim nItemDate(0)
sItemNums(0) = ""
nItemDesc(0) = ""
nItemCost(0) = 0.00
nItemDate(0) = ""

IF request("removedate") <> "" THEN
    For i = 0 to uBound(session("cartitemnumarray"))
        IF cstr(session("cartitemdatearray")(i)) <> cstr(request("removedate")) THEN
            ReDim Preserve sItemNums(nItemCount)
            ReDim Preserve nItemDesc(nItemCount)
            ReDim Preserve nItemCost(nItemCount)
            ReDim Preserve nItemDate(nItemCount)
            sItemNums(nItemCount) = session("cartitemnumarray")(i)
            nItemDesc(nItemCount) = session("cartitemdescarray")(i)
            nItemCost(nItemCount) = session("cartitemcostarray")(i)
            nItemDate(nItemCount) = session("cartitemdatearray")(i)
            nItemCount = nItemCount + 1
        END IF
    NEXT
    nItemCount = nItemCount - 1
    session("cartitemnumarray") = sItemNums
    session("cartitemdescarray") = nItemDesc
    session("cartitemcostarray") = nItemCost
    session("cartitemdatearray") = nItemDate
ELSEIF request("addlunch") <> "" THEN

FOR iForm = 1 to int(Session("iFrm"))
 IF cstr(session("cartitemdatearray")(i)) = cstr(request("date"+cstr(request(IForm)))) THEN
   'HERE'S WHERE I WOULD LIKE TO DELETE THE CURRENT ITEMS
NEXT

--END OF CODE

Thanks in advance
Chris

 
Old September 14th, 2006, 08:41 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

The question is are you trying to remove the dimension of the array or just trying to delete (read as, set to NULL) the value at X element of your array?

"The one language all programmers understand is profanity."
 
Old September 14th, 2006, 11:29 AM
Registered User
 
Join Date: Sep 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks.

I would like to - I think - remove the dimension of the array. I want to remove all parts of what is stored in that particular section(dimension? not sure if the terminology is correct). So, date, product, number of items, cost. IOW, the whole item that pertains to that date.

Chris

 
Old September 14th, 2006, 11:50 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

This may not be the most effecient way to do this, but it will work.

Create a tempArray that has exactly as many dimensions as your main session array then clear your session array; loop through the temp Array and when a data item that matches your critera is found, dont add it back to the session array, trim your main session array down to its number o dimensions and set your temp array to nothing.

Unfortunately, redim preserve wont work here because if the element you want to remove is in the middle of the array, anything following that element will be erased as well.

hth

"The one language all programmers understand is profanity."
 
Old September 14th, 2006, 12:23 PM
Registered User
 
Join Date: Sep 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'll give it a try. Thanks for the help.

Chris

 
Old September 14th, 2006, 12:30 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Your very welcome.

"The one language all programmers understand is profanity."





Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete item from array sektor Excel VBA 16 April 30th, 2008 04:36 AM
Deleting a row of an array Singh591 VB.NET 2002/2003 Basics 1 July 23rd, 2007 04:51 PM
Getting an item from the array monfu C# 0 March 29th, 2006 09:21 AM
Want Combo Box first item if only 1 item markw707 Access 3 June 9th, 2004 04:03 PM
Remove item from an array? jefferis PHP How-To 5 November 27th, 2003 11:38 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.