Active Server Pages/Hints
Categories: Articles that need to be wikified
Use Option Explicit
Place this in the first file that gets called in your ASP page. It will force you to declare any variables that you use and stop typo's
Make use of include files for site wide functionality
This will allow you to specify common site variables (database connection strings), and common functions ( sendMail?) in one place on your site. This can also be used for templating a site (top.asp / bottom.asp).
Use Functions and Subs to encapsulate code
This puts a level of scope on your variables and stops different things interfering with each other.
Use some kind of hungarian style notation ( str, int, lng, obj), for variables
This will help you figure out what each variable is as you use it. For example there was the merit table posting on here, what is merittable? rsMeritTable would have given everyone a much better clue.
Use Friendly variable names
There isn't any reason why you would want to name a variable "x" when it could be "intPage"
Comment code
You might not otherwise remember why you did it that way in a couple of months time
Where possible try and split your code into the appropriate layer
The standard three tiers of development are data, business and presentation. Try to keep these apart in your code and everything will work much better.
Avoid arrays etc. like the plague
The RecordSet object is perfectly nice to work with, stop trying to pull data into nameless arrays. What reads better: Code:
arrFood(3)
or Code:
rsFood("Flavour")
ummm... no. GetRows is better: http://www.learnasp.com/advice/whygetrows.asp
How about 1 transfer instead of 3500?
A better alternative code approach is GetRows!
Rules of Thumb
- If is seems impossible it's likely you're doing it wrong.
- They who google first are unlikely to be shot down in flames
- Those error numbers really do mean something, try searching
- If you're having to debug more than 30 lines of code you've not encapsulated enough
- If you have to jump through more than 3 functions/subs to debug a problem you've encapsulated too much.