473,783 Members | 2,563 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calculating a Subtotal for Shopping Cart

I'm trying to calculate the subtotal for each item the customer has in
the shopping cart. objDataReader(" decPrice") is the price from my
database field called decPrice. The .8 is for a 20% discount. The
error I get is:

Compiler Error Message: BC30201: Expression expected.

What is the correct syntax for this operation? When I check the
compiler output there is a ~ underneath the &. Any help would be
greatly appreciated.

<!-- CODE SNIPPET -->

Dim strSubTotal as string = 0
Dim i as integer = 0
FOR i = 0 to gtCart.count -1
dim strItemID as string = ds.Tables("tblS Cart").rows(i)( "ItemID")
ds.Tables("tblS Cart").rows(i)( "Qty") = gtCart(strItemI D)
strSubTotal = .8 * & objDataReader(" decPrice")
NEXT

<!-- CODE SNIPPET -->

Nov 19 '05 #1
6 2941
Hi,

Try this:

strSubTotal = CStr(.8 * CDec(objDataRea der("decPrice") ))

Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"Sparky Arbuckle" <tw*@secureroot .com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
I'm trying to calculate the subtotal for each item the customer has in
the shopping cart. objDataReader(" decPrice") is the price from my
database field called decPrice. The .8 is for a 20% discount. The
error I get is:

Compiler Error Message: BC30201: Expression expected.

What is the correct syntax for this operation? When I check the
compiler output there is a ~ underneath the &. Any help would be
greatly appreciated.

<!-- CODE SNIPPET -->

Dim strSubTotal as string = 0
Dim i as integer = 0
FOR i = 0 to gtCart.count -1
dim strItemID as string = ds.Tables("tblS Cart").rows(i)( "ItemID")
ds.Tables("tblS Cart").rows(i)( "Qty") = gtCart(strItemI D)
strSubTotal = .8 * & objDataReader(" decPrice")
NEXT

<!-- CODE SNIPPET -->

Nov 19 '05 #2

The error is here:

strSubTotal = .8 * & objDataReader(" decPrice")

If you want to add ".8 *" as string do it in the following way:

strSubTotal = ".8 *" & objDataReader(" decPrice")

But if you want to multiply the value of objDataReader(" decPrice") by .8 and
then convert the value to string

strSubTotal = CType(0.8 * CType(objDataRe ader("decPrice" ), Double), string)
Best regards,

Gaidar
"Sparky Arbuckle" <tw*@secureroot .com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
I'm trying to calculate the subtotal for each item the customer has in
the shopping cart. objDataReader(" decPrice") is the price from my
database field called decPrice. The .8 is for a 20% discount. The
error I get is:

Compiler Error Message: BC30201: Expression expected.

What is the correct syntax for this operation? When I check the
compiler output there is a ~ underneath the &. Any help would be
greatly appreciated.

<!-- CODE SNIPPET -->

Dim strSubTotal as string = 0
Dim i as integer = 0
FOR i = 0 to gtCart.count -1
dim strItemID as string = ds.Tables("tblS Cart").rows(i)( "ItemID")
ds.Tables("tblS Cart").rows(i)( "Qty") = gtCart(strItemI D)
strSubTotal = .8 * & objDataReader(" decPrice")
NEXT

<!-- CODE SNIPPET -->

Nov 19 '05 #3
Thanks for the prompt reply Ken. Now I get a new error:

Exception Details: System.NullRefe renceException: Object reference not
set to an instance of an object.

Nov 19 '05 #4
Gaidar:

I get the same error when I try your example. Maybe more insight would
be had if I were to tell the group that I am binding this information
to a dataGrid?

Nov 19 '05 #5
May be you will post complete code of the class?

"Sparky Arbuckle" <tw*@secureroot .com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
Gaidar:

I get the same error when I try your example. Maybe more insight would
be had if I were to tell the group that I am binding this information
to a dataGrid?

Nov 19 '05 #6
You got it:

Sub UpdateCookie(by Ref gtCart as HashTable)

'Retrieve querystring parameters
Dim strDelete as string = Request.queryst ring("Delete")
Dim strAdd as string = Request.queryst ring("Add")

'If no changes to cookie then return
IF strDelete < " " and strAdd < " " THEN RETURN

IF strDelete > " " THEN
IF gtcart.Contains (strDelete) THEN
IF gtCart(strDelet e) = 1 THEN
gtCart.remove(s trDelete)
ELSE
gtCart(strDelet e) = gtCart(strDelet e)-1
END IF
ELSE
Response.Write( "No such ASIN in cart: " & strDelete & "<br>")
RETURN
END IF
END IF

IF strAdd > " " THEN
IF gtCart.Contains (strAdd) THEN
gtCart(strAdd) = gtcart(strAdd) + 1
ELSE
gtCart(strAdd) = 1
END IF
END IF

'Delete cookie if empty. This eliminates empty "ghost" key.
IF gtCart.count = 0 THEN
Response.Cookie s(MyCookieName) .Expires = Now.AddDays(-1)
RETURN
END IF

'Write HashTable back to cookie
Dim MyCookie as new httpCookie(MyCo okieName)

Dim iCount as integer = 0
Dim objConn as new
OLEDBConnection (ConfigurationS ettings.AppSett ings("StrConnec tion"))
Dim strSQL as string = "SELECT ASIN, strTitle, strArtist, decPrice,
strLabel, intNumberDisks, dtReleaseDate, strReview, strImageDir " & _
"FROM tblDescription WHERE "

FOR EACH myItem as DictionaryEntry in gtCart
iCount = iCount + 1
MyCookie.Values (myItem.Key) = myItem.Value

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

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

ELSE

strSQL += ";"
END IF

Response.Cookie s("Customer")(" Quantity") = MyItem.Value

NEXT

Dim objDataReader as OLEDBDataReader
objConn.Open()

Dim objCommand as new OLEDBCommand(st rSQL,objConn)

Dim myCommand as new OleDbDataAdapte r(strSQL, objConn)
myCommand.Fill( ds, "tblSCart")
ds.Tables("tblS Cart").Columns. Add("Qty")

Dim strSubTotal as string = 0
Dim i as integer = 0
FOR i = 0 to gtCart.count -1
dim strASIN as string =
ds.Tables("tblS Cart").rows(i)( "ASIN")
ds.Tables("tblS Cart").rows(i)( "Qty") = gtCart(strASIN)
strSubTotal = ".8 *" & objDataReader(" decPrice")
NEXT

lblShipping.tex t = 0
lblSubTotal.tex t = strSubTotal
lblGrandTotal.t ext = 0

dgSCart.DataSou rce = ds.Tables("tblS cart").DefaultV iew
dgSCart.DataBin d()

'Write cookie to page
Response.Cookie s.Add(MyCookie)
Response.Cookie s(MyCookieName) .Expires = Now.AddDays(30)

FOR EACH myItem as DictionaryEntry in gtCart
MyCookie.Values (myItem.Key) = myItem.Value

NEXT

END Sub

Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2869
by: Don Grover | last post by:
I am retrieving costs and product id's from a sql db. and need to build a shopping cart around it. How do I store the selected items and qty req so I can move into another catalog and total up as im going. Just a couple of hints will do, Im familiar with vb script but not java based code , and im wondering how to store what they select so I can move around different product ranges. Don
2
3317
by: Paul Bruneau | last post by:
Hi, I hope someone can help me make a working shopping cart, as a learning tool. If I have a "Product Demo" html page with a "Buy Me" button, there must be a simple javascript method of storing the necessary product information. There could be several fields involved... Then there ought to be another javascript method that can create a new document based on the list a user has built selecting product from several
1
3583
by: madison | last post by:
Hi, I am trying to start a website using paypals shopping cart function. If i have 10 items and they sell out, how do I make it so the item is then listed as sold out. The next person would not be able to come along and add it to their shopping cart. thanks joy
1
1822
by: Jia Sun | last post by:
hello , everybody , i need a similar program , just like fancyimport.com if possible, pls contact me ,thank you very much . inchina@gmail.com
1
3230
by: Adil Akram | last post by:
I have created a site shopping cart in ASP.net. I am using ASP session object's SessionID on non SSL connection to track session. While adding products to cart DB I insert product and SessionID in table. All products and cart status pages are on non SSL connection. On checkout to get secure user information I shifted connection to SSL but when shifting to SSL, the SessionID changed (As is this is default behavior of IIS to prevent...
2
1732
by: Sparky Arbuckle | last post by:
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...
2
2301
by: G.E.M.P | last post by:
High Level Session Handling Design for a Shopping cart 0) What am I missing? 1) How does OSCommerce do it? I'm thinking about building a shopping cart from scratch, using a library of dynamic screen generation routines (already written) that take an XML stream as input from various "search for products" forms. That way I can run queries in one window and display the dynamic results in another. The searching functions will probably
1
7300
by: jecha | last post by:
I'm implementing a shopping cart but am having a problem in checking out a person who has added item in his/her shopping busket.The code for the checkout.php script is given below <? require_once('functions.inc.php'); session_start(); do_html_header("Checkout"); $cart = $_SESSION; if($cart&&array_count_values($cart)) { display_cart($cart,false,0); display_checkout_form($HTTP_POST_VARS);
3
2895
by: Paulo | last post by:
Hi, beginner on asp.net 2.0 C# VS 2005, how can I use the shopping cart concept on my application? When the user clicks add item, it will be stored on some storage format, I dont know what is the term: temp/global DataSet, etc... and it should be read on other web-form to checkout the items... Can you point me to the right direction? Thank you very much!
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10315
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10083
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.