ASP 101 - Active Server Pages 101 - Web06
The Place ASP Developers Go!

Please visit our partners


Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates














ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash



 Top ASP 101 Stories Top ASP 101 Stories
Getting Scripts to Run on a Schedule
The Top 10 ASP Links @ Microsoft.com
What is Adovbs.inc and Why Do I Need It?

QUICK TIP:
Attach Files from Interdev to Email Messages Easily
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates


Quick Tips


Dim Even When Not Using Option Explicit

If for any reason you ever find yourself not using Option Explicit (IE: maintaining someone else's old code), you should still dimension all the variables you use. A dimensioned variable works almost twice as fast as an implicitly created variable.

If you do a speed test on:

For lngCnt = 1 To 1000000000
Next

compared to:

Dim lngCnt
For lngCnt = 1 To 1000000000
Next

you will find that the second one finishes much faster.

When you dimension your variables, it's best to do so at the top of the page. Some people tend to dimension them just before they are used, but that makes it difficult to see what variables are used, often leads to less readable code, and can even cause problems:

A Dim statement is always executed, even if it is inside a code section that isn't. This is because the Dim statements are executed first when compiling to reserve the required memory. For example, this will give you a "Name Redefined" error:

If False Then
    Dim lngCnt '<---- Always Executed
End If
Dim lngCnt '<---- Will Cause an Error

 

Thanks go out to Göran Andersson for this Quick Tip.


Previous      Show All Tips      Next

If you have a tip you would like to submit, please send it to: webmaster@asp101.com.


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers