ASP Tips

By ServerWatch Staff (Send Email)
Posted May 6, 1999


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.

  1. Buy a magic 8-ball (I use this for debugging)
  2. 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.

  3. 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'")


    Use this instead:

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

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

    Response.Write SQL

  4. 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 %>

  5. 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.

If you have any comments or questions feel free to e-mail me.

Page 1 of 1


Comment and Contribute

Your name/nickname

Your email

(Maximum characters: 1200). You have characters left.