The Four Word Film Review Fourum
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

Return to my fwfr
Frequently Asked Questions Click for advanced search
 All Forums
 Off-Topic
 General
 Show and Tell
 New Topic  Reply to Topic
 Send Topic to a Friend
 Printer Friendly
Author Previous Topic Topic Next Topic  

duh 
"catpurrs"

Posted - 02/18/2007 :  06:53:28  Show Profile  Reply with Quote
OK, so I've been working on this web coding project (sort of a classifieds for a client) for the past couple of weeks, nearly 24/7. In the process I've had to learn how to do some things with ASP that I didn't know how to do before.

For example, I decided that on the ad submission forms, the price field needed to be sanitized to make sure the correct numerical value went into the database.

I'm not good with numbers at all but ASP requires logic, which is a bit easier for me.

Anyhow, after I got it all figgered out I wrote up another tutorial on it. You can see it HERE. I'm not clever like the younger, cuter and smarter Benj, which makes it all the more satisfying to get something like this to work.

In fact, if I'm lucky, Benj will suggest a more efficient way to do the same thing. (hint hint)

ChocolateLady 
"500 Chocolate Delights"

Posted - 02/18/2007 :  07:05:46  Show Profile  Reply with Quote
Sanitize prices? What is this? A new type of money laundering?
Go to Top of Page

benj clews 
"...."

Posted - 02/18/2007 :  13:36:09  Show Profile  Reply with Quote
I simplified the d.p. cropping code a bit- if you're not bothered about rounding up or down, you could even remove the ELSE condition entirely and leave the formatNumber function to do the majority of the work for you.

Also, I wasn't sure what you wanted to be output in the instance of the input not being a number, so I've defaulted the code to make it 0.00

I also added in a check to see if the input value was "". Quite often an isNumeric check on such a value will say it is a number (0), so I've written the code to deal with this too.

<%
dim strOurValue

strOurValue = request.form("PRICE")

'Let's sanitize our Price field

'OK let's first make sure the price string is numeric
if NOT isNumeric(strOurValue) or (trim(strOurValue) = "") then
response.write "Not a number." ' you could put in code to remove nonnumeric characters
strOurValue = 0

else
strOurValue = strOurValue * 100 'Shift the d.p two places to the right
strOurValue = int(strOurValue) 'Remove anything after the d.p. now
strOurValue = (strOurValue / 100) 'Shift the d.p. back two places to the left

end if

strOurValue = FormatNumber(strOurValue, 2)

response.write "<br>The sanitized Price is: $" &strOurValue ' and write it out
%>
Go to Top of Page

Whippersnapper. 
"A fourword thinking guy."

Posted - 02/18/2007 :  13:53:00  Show Profile  Reply with Quote

Couldn't have put it better myself.

()
Go to Top of Page

duh 
"catpurrs"

Posted - 02/18/2007 :  16:50:47  Show Profile  Reply with Quote
quote:
Originally posted by benj clews

I simplified the d.p. cropping code a bit- if you're not bothered about rounding up or down, you could even remove the ELSE condition entirely and leave the formatNumber function to do the majority of the work for you.

Also, I wasn't sure what you wanted to be output in the instance of the input not being a number, so I've defaulted the code to make it 0.00

I also added in a check to see if the input value was "". Quite often an isNumeric check on such a value will say it is a number (0), so I've written the code to deal with this too.

<%
dim strOurValue

strOurValue = request.form("PRICE")

'Let's sanitize our Price field

'OK let's first make sure the price string is numeric
if NOT isNumeric(strOurValue) or (trim(strOurValue) = "") then
response.write "Not a number." ' you could put in code to remove nonnumeric characters
strOurValue = 0

else
strOurValue = strOurValue * 100 'Shift the d.p two places to the right
strOurValue = int(strOurValue) 'Remove anything after the d.p. now
strOurValue = (strOurValue / 100) 'Shift the d.p. back two places to the left

end if

strOurValue = FormatNumber(strOurValue, 2)

response.write "<br>The sanitized Price is: $" &strOurValue ' and write it out
%>



Fantastic! Thank you, Mr. Benj!!!!!!!!
Edit: The thought just occurred to me -- of course a guy who invented four word film reviewing is going to write lean code!

Edited by - duh on 02/18/2007 17:05:24
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Send Topic to a Friend
 Printer Friendly
Jump To:
The Four Word Film Review Fourum © 1999-2024 benj clews Go To Top Of Page
Snitz Forums 2000