FOR EACH - NEXT SubTotal Calculation

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

From: Sparky Arbuckle (twa_at_secureroot.com)
Date: 02/22/05


Date: 22 Feb 2005 00:02:56 -0800

Hello All! My problem is trying to calculate SubTotal in my FOR EACH
NEXT Loop. I am looping through depending on how many of each different
item is in the user's shopping cart. I am using each Item ID in the
cart to display the appropriate image, artist name, and price
information for each item in the cart. I am running into problems when
I try and display the subtotal and add a count of each item in the
shopping cart. More importantly I am trying to come up with the
SubTotal. Here is the snippet of code for my loop:

<----------------------------------------------------->

   Dim MyCookie as new httpCookie(MyCookieName)
   Dim intCount as integer = 0
   Dim intSubTotal as integer = 0

   Dim objConn as new
OLEDBConnection(ConfigurationSettings.AppSettings("StrConnection"))
   Dim strSQL as string = "SELECT ITEM ID, imageDIR, Price, ReleaseDate
FROM tblDescription WHERE "

   FOR EACH myItem as DictionaryEntry in gtCart
   intCount = intCount + 1
   intSubTotal = intSubtotal * .8
   MyCookie.Values(myItem.Key) = myItem.Value

   strSQL += "ITEMID= '" & myItem.Key & "'"

   IF intCount < gtCart.Count
   strSQL += " OR "

   ELSE

   strSQL += ";"
   END IF

   NEXT

<----------------------------------------------------->

The FOR EACH NEXT Loop that I have listed works magnificently for
figuring out if I have multiple items in my shopping cart and displays
everything perfectly. I try to reference intSubTotal (20% off each) in
the body of my page (nested inside of my FORM runat="Server") and it
does not work. Can anyone shed some light on how to go about creating a
variable for SubTotal and displaying it on my page?

SideNote: myItem.Value is how many of each ITEMID is in the shopping
cart. How can I reference this in my DataGrid?



Relevant Pages

  • Re: HELP! ASP and SQL problem.
    ... >>> to a database and also display that information in an edit mode. ... >>> DIM objConn ... >>> objRS.Open mySQL, objConn ... >>> Loop ...
    (microsoft.public.inetserver.asp.general)
  • Programming loops inside repeater controls
    ... I'm trying to display groups of records with the repeater control in a ... Dim strConn as string ... I'm trying to loop thru the database until i run out of records: ...
    (microsoft.public.dotnet.general)
  • Re: Commandbutton captions
    ... Private Sub UserForm_Initialize ... Dim N As Long ... and a macro sizes it to display only those needed. ... any way to index the button reference in a loop. ...
    (microsoft.public.excel.programming)
  • Re: Numbered List Count?
    ... Put a bookmarked named "ListCnt" where you want to display the list ... Dim R As Range, ListCnt As Integer ... Loop While R.Find.Found ...
    (microsoft.public.word.numbering)
  • Re: Looping through Query to create multiple sheets in excel- Just need the loop
    ... I always get to this point and I can't figure out how to loop through ... I have put the string in the query at the bottom. ... Optional strWorkSheet As String, Optional strRange As ... Dim objXLSheet As Object 'Excel.Worksheet ...
    (microsoft.public.access.forms)