[thelist] ASP

Paul Cowan paul at wishlist.com.au
Tue Aug 14 18:30:58 CDT 2001


Hi all,

Alastair Murdoch [mailto:alastair at cubeit.co.uk] wrote:
> Cint() to cast to integer and CStr() to cast to string.

Well, I can't let that pass without offering the following tip:

<tip type="ASP Headache Prevention" author="Paul Cowan">
You may find it useful to make sure that your development team
minimise the use of the asp CInt() function, in favour of CLng().
In fact, you might even like to BAN CInt() outright in your coding
standards (you DO have coding standards, right?). For the extremely
anal, you can do what we did and write a "Plugin" for your source 
control program (you DO use a source control program, right?) which
will NOT ALLOW checkin if the CInt() function is used.

Why? Well, it's simple. CInt() is restricted to the maximum length
of an integer, which means it won't cope with a number greater than
32,767. CInt("32768") will cause your page to fail. When
using CInt() to validate user input, you can never be sure they won't
"typo" and enter a number that's too large. When using it to track
IDs passed from page to page, you should follow Cowan's Law #1: 
if you think that you could never ever ever have more than 
32,000 [customers|products|articles|...], you are bound to 
look extremely foolish when you launch your 32,768th
[customer|product|article|...] and have to go and replace all 
your CInt()s with CLng()s anyway... CLng()s will cope with numbers up
to (from memory) 4 billion (that's US billion, by the way).
</tip>




More information about the thelist mailing list