Multiplication Problem

# Thread: Multiplication Problem

1. Junior Member
Join Date
Dec 1969
Posts
2

## Multiplication Problem

I am trying to multiply 2 numbers but keep getting this error "<BR><BR>"Microsoft VBScript runtime error &#039;800a000d&#039; Type mismatch "<BR><BR>the code looks like this :<BR><BR> thePrice = ss("Price") &#039;&#060;&#060;&#060; this is a value from a db query<BR> total = theQuantity * thePrice <BR><BR> example... total = 6 * 14.95<BR><BR>I dont understand why i am getting the error.<BR><BR>

2. jpn
Senior Member
Join Date
Dec 1969
Posts
687

## use cval

&#060;eop&#062;

3. Senior Member
Join Date
Dec 1969
Posts
2,049

## RE: Try

Â*<BR><BR>thePrice = ss("Price") <BR><BR>If IsNumeric(thePrice) And IsNumeric(theQuantity) Then<BR> total = theQuantity * thePrice <BR>Else<BR>Response.Write "Q: "& theQuantity & _<BR>"&#060;BR /&#062;P: "& thePrice<BR>End If<BR><BR><BR>jc<BR>

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## What in the world is CVAL???

Never heard of it.

5. Senior Member
Join Date
Dec 1969
Posts
96,118

## If your DB field type is DECIMAL

...then VBS doesn&#039;t understand DECIMAL data, hence the error.<BR><BR>VBS can pass along a DECIMAL, a to Response.Write, but it can&#039;t compute with it.<BR><BR>To allow computation, you need to convert it to a type that VBS *does* understand, and DOUBLE is the best match. So use the CDBL function:<BR><BR>thePrice = CDBL( ss("Price") )<BR>total = theQuantity * thePrice<BR><BR>Naturally, it theQuantity might also be DECIMAL, you need to convert it as well. (But it&#039;s probably an integer, so you are probably okay.)<BR><BR>CAUTION: *ALL* values you get from form fields via Request.QueryString("xxx") or Request.Form("yyy") are *STRINGS*. They, also, should *ALWAYS* be converted.<BR><BR>

6. Senior Member
Join Date
Dec 1969
Posts
2,049

## RE: If your DB field type is DECIMAL

What if<BR><BR>thePrice = null<BR><BR>or<BR><BR>theQuantity = null<BR><BR>would that create an error you way?<BR>Or are we assuming they will always be a number?<BR><BR>I was curious if values are being passed or not.<BR><BR>jc<BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•