ASP Help

Sphexi

Diamond Member
Feb 22, 2005
7,280
0
0
I feel stupid for having to ask, but ASP is not something I generally do, it's mostly something I'm playing with to make my job easier. The script below is supposed to display one of 3 messages, depending on how much trnAmount is. Anything under 10.00 works fine and displays message1, but over 10.00 it displays message3 always, never message2.

<%

if (request("trnAmount") < "10.00") then
response.write("message1")

elseif (request("trnAmount") >= "10.00" and request("trnAmount") < "100.00") then
response.write("message2")

elseif (request("trnAmount") >= "100.00") then
response.write("message3")

end if

%>

Any ideas?
 

Snapster

Diamond Member
Oct 14, 2001
3,916
0
0
It's because you are comparing it to a string, try this instead:


' Put here so you can sanitize the input in one place
amount = request("trnAmount")

if (amount < 10.00) then
response.write("message1")

elseif (amount >= 10.00 and amount < 100.00) then
response.write("message2")

elseif (amount >= 100.00) then
response.write("message3")

end if
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
First, you can't compare strings the way you are and expect results based on apparent numeric values. I'm not even sure what the '<' or other comparison operators do for strings.

Second, I haven't seen the request object used the way you're trying to use it. The request object has two collections, Form and Querystring, that you might use to get passed values depending on whether it's a form post or a url get. In ASP's case it is always a form post, so..


if ( Convert.ToInt32(request.Form("trnAmount")) < 10 ) then
response.write("message1")

etc.

But of course this isn't safe, because you don't know whether the string in Request("trnAmount") actually represents a number. You should validate that input before passing it to Convert, or handle the possible exceptions and react accordingly.
 

Sphexi

Diamond Member
Feb 22, 2005
7,280
0
0
trnAmount will always be a number, this is the last step in a payment processing setup. The original POST string goes through our system, is processed and approved, and then passed back to either this code which is just a small part of the approval page, or the merchant to parse out in their own approval page. I'm just trying to make that page display different text based on the amount submitted, rather than a static "Approved" message.


Edit:

Also, Snapster's response worked perfectly, all three messages show up as intended. If I get everything to the point of being hosted on my own site rather than our internal system, I'll post a link to play with. Thanks for the help!
 

nakedfrog

No Lifer
Apr 3, 2001
63,657
20,119
136
Originally posted by: Markbnj
The Form property is probably the default for the Request object, now that I think about it.

It's dirty but it works :p
 

Sphexi

Diamond Member
Feb 22, 2005
7,280
0
0
Well I've been bored at work, so I threw up a generic test form. You can put in your email address and name, and any amount you want, and you'll get to the approval page, and get a wonderful little receipt email.

http://pirates.sphexi.com