ASP Tips

These tips are pretty basic and can be found anywhere on the net, but they still can help your code.Ian Stallings
These tips are pretty basic and can be found anywhere on the net,
but they still can help your code.

Buy a magic 8-ball (I use this for debugging)

Store COM values once
When using values returned through COM you can store them locally to make your
code more efficient. For example, instead of this:

If Session("data") = "something" Then
Response.Write "something"
end if
If Session("data") = "nothing" Then
Response.Write "nothing"
end if
Use this:

data = Session("data")

If data = "something" Then
Response.Write "something"
end if
If data = "nothing" Then
Response.Write "nothing"
end if

This way you not making a call for the same data over and over.

Put SQL in a variable

Instead of just executing the SQL statement directly
like so:

Set SQL = oConn.Execute("SELECT * FROM MasterAccounts WHERE Login='ian'")

This way you can write the info to the screen
when you debug using the response object like this:

Response.Write SQL

Use Option Explicit in VBscript

When putting code into production try to
use the 'Option Explicit' option in VBscript.
This makes you declare each variable before they
can be used. Undefined variables are a performance
leech. You can use the following to turn this on:

<% option explicit %>

Place common functions in include file

If you have a common function that you want to
use over and over, such as one to validate an
email address, place it in include file
(preferably in a common directory) and then you
can access it from any page you want.