ASP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingASP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 16th, 2002, 10:14 AM
aspnewbie aspnewbie is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: The Great White North
Posts: 361 aspnewbie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 50 sec
Reputation Power: 7
Send a message via MSN to aspnewbie
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.

Reply With Quote
  #2  
Old October 20th, 2002, 01:15 PM
rdoekes rdoekes is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Strasbourg, France
Posts: 181 rdoekes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 20 sec
Reputation Power: 7
Send a message via AIM to rdoekes Send a message via Yahoo to rdoekes
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.

Reply With Quote
  #3  
Old October 20th, 2002, 10:41 PM
aspnewbie aspnewbie is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: The Great White North
Posts: 361 aspnewbie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 50 sec
Reputation Power: 7
Send a message via MSN to aspnewbie
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.

Reply With Quote
  #4  
Old October 21st, 2002, 04:18 AM
rdoekes rdoekes is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Strasbourg, France
Posts: 181 rdoekes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 20 sec
Reputation Power: 7
Send a message via AIM to rdoekes Send a message via Yahoo to rdoekes
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.

Reply With Quote
  #5  
Old October 22nd, 2002, 12:27 PM
aspnewbie aspnewbie is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: The Great White North
Posts: 361 aspnewbie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 58 m 50 sec
Reputation Power: 7
Send a message via MSN to aspnewbie
Smile

fantastic. thanks again!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingASP Development > Error Message is Not Being Displayed - Please Help!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT