Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error with Numbers containing decimals (Currency)

Status
Not open for further replies.

Rexolio

Technical User
Aug 29, 2001
230
Hi all,

I have a form where sales people enter their new contracts include 3 different billing fields. At least one of these billing fields must contain an amount other than zero (our sales people are bad about entering contracts without the amounts.) All fields are default to "0".

So, on the processing page, before anything is added to our database, I do the following:

Code:
Billing1 = Request("Billing1")
Billing2 = Request("Billing2")
Billing3 = Request("Billing3")

CheckAmount = Billing1 + Billing2 + Billing3

if CheckAmount = 0 then
     Response.redirect("form1.asp?ERROR=Yes")
     Response.end
else
     'then i add the database insert stuff here
end if

Most of the time it works without a problem. But occasionally they are getting the following error:

Microsoft VBScript runtime error '800a000d'
Type mismatch: 'CheckAmount'
/contracts/form2.asp, line 112


Now, I know this happens when someone enters the letter "0" instead of a zero, or they enter someone characther. But its also happening when the user either enters ".00" after the dollar amount, or enters something like ".50" or another cent value in MORE THAN ONE field. If they just add a cent value in one field, no problem. If they add a cent value in more than one field or they add ".00" in any field, this error occurs.

What can I do about this?

Thanks!




[bugeyed]
rexolio@bellsouth.net
"I'm not dumb. I just have a command of thoroughly useless information." - Calvin, of Calvin and Hobbes
 
try a datatype conversion function for long integer

____________________________________________________
$str = "sleep is good for you. sleep gives you the energy you need to function";
$Nstr = ereg_replace("sleep","coffee",$str); echo $Nstr;

onpnt2.gif
 
The error I'm getting has nothing to do with the insertion of the information into the database (sorry for not pointing this out.) The error is occuring on the line:

Code:
CheckAmount = Billing1 + Billing2 + Billing3

Any suggestions?

[bugeyed]
rexolio@bellsouth.net
"I'm not dumb. I just have a command of thoroughly useless information." - Calvin, of Calvin and Hobbes
 
...give this a try...

Code:
Billing1 = Request("Billing1")
Billing2 = Request("Billing2")
Billing3 = Request("Billing3")
 
if Billing1 = "" then Billing1 = 0 else Billing1 = CDbl(Billing1) end if
if Billing2 = "" then Billing2 = 0 else Billing2 = CDbl(Billing2) end if
if Billing3 = "" then Billing3 = 0 else Billing3 = CDbl(Billing3) end if

CheckAmount = Billing1 + Billing2 + Billing3

...or you can start testing your Billing Fields prior to form-submission via Javascript...

With javascript and a Regular Expression, you could prevent any non-numeric values from getting passed, and ensure that fields got set to ZERO, rather than EMPTY.

No time now to provide sample code... maybe tomorrow.
 
The error I'm getting has nothing to do with the insertion of the information into the database

Yes, I realized that but you can't add strings together.
as Mr3Putt has shownt he use of the Cdbl() function

____________________________________________________
$str = "sleep is good for you. sleep gives you the energy you need to function";
$Nstr = ereg_replace("sleep","coffee",$str); echo $Nstr;

onpnt2.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top