|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Error Message is Not Being Displayed - Comparison of 2 Amounts
Can someone tell me why my error message isn't being displayed when the new bid is less than the current bid? Instead, the new bid is being added to the database. Here's the code. Thanks a lot!
Code:
dim iCurrentBid, iBidAmount, iItemID ' as integer
dim strCurrentBidderEmail 'as string
iItemID = Request.Form("intItemID")
iCurrentBid = Request.Form("intCurrentBid")
strCurrentBidderEmail = Request.Form("txtBidderEmail")
iBidAmount = Request.Form("intBidAmount")
'debugging lines
'Response.Write iCurrentBid
'Response.Write iBidAmount
if iBidAmount < iCurrentBid then
Response.Write "Your bid must be higher than the last bid"<br><br>"
Response.Write "<b>Your Bid</b> was " & iBidAmount & "<br><br>"
Response.Write "<b>The Current Bid</b> is " & iCurrentBid & "<br>"
Response.Write "<a href=""bidform.asp?itemid=" & iItemID &_
""">"
Response.Write "Return to Bid Form</a>"
else
'add the bid to the database
end if
The iBidAmount and iCurrentBid are formated as formatCurrency, 2. Last edited by aspnewbie : October 16th, 2002 at 07:20 PM. |
|
#2
|
|||
|
|||
|
use CInt
Hi aspnewbie,
I had these type of problems before. I found that this solution works fine: 1. in case of integer comparison Code:
if CInt(iBidAmount) < CInt(iCurrentBid) then 2. in case of numeric comparison: Code:
if CDbl(iBidAmount) < CDbl(iCurrentBid) then I believe the rational behind is that ASP is weakly typed, so it treats every variable as a variant. This way you make numeric values of your variables. The FormatNumber is only for print purposes, it will not have a real effect on the variables. Before you execute this script ensure the user input is numeric by using a regular expression (either as a javascript validation that kicks in with the onSubmit event, or server side in asp) or a test on IsNumeric. This is important because CInt and CDbl with return asp error messages if the variable is not numeric. Thanks,
__________________
- Rogier Doekes Last edited by rdoekes : October 20th, 2002 at 06:34 PM. |
|
#3
|
|||
|
|||
|
That makes eminent sense - thanks, I'll give it a try.
Can you help me out on the regular expression/isNumeric bit, per chance? I realized that I would need to ensure the user enters a number and need validation, but one javacript I tried didn't work as I had hoped. |
|
#4
|
|||
|
|||
|
reg expr function
Server side reg exp checking function
Code:
Function CheckValue(sPattern, sInput)
Dim oRegExp
Set oRegExp = New RegExp
'find all matches (don't stop at first hit)
oRegExp.Global = True
'ignore case sensitive
oRegExp.IgnoreCase = True
'set pattern
oRegExp.Pattern = sPattern
CheckValue = oRegExp.Test(sInput)
Set oRegExp = Nothing
End Function
This function can now be used for testing the contents: 1. integer testing Code:
If NOt CheckValue("[0-9]", Request.Form("intCurrentBid"))
'error handling
End IF
2. numeric testing Code:
If Not CheckValue("^[0-9]+[.][0-9]{2}$", Request.Form("intCurrentBid")) Then
'error handling
End If
same for the bid amount. |
|
#5
|
|||
|
|||
|
fantastic. thanks again!
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > ASP Development > Error Message is Not Being Displayed - Please Help! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|