Web Development

  Homes arrow Web Development arrow Option Explicit
 Webmaster Tools
Base64 Encoding 
Browser Settings 
CSS Coder 
CSS Navigation Menu 
Datetime Converter 
DHTML Tooltip 
Dig Utility 
DNS Utility 
Dropdown Menu 
Fetch Content 
Fetch Header 
Floating Layer 
htaccess Generator 
HTML Encoder 
HTML Entities 
IP Convert 
Meta Tags 
Password Encryption
Password Strength
Pattern Extractor 
Ping Utility 
Pop-Up Window 
Regex Extractor 
Regex Match 
Scrollbar Color 
Source Viewer 
Syntax Highlighting 
URL Encoding 
Web Safe Colors 
Forums Sitemap 
Weekly Newsletter
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Contact Us 
Site Map 
Privacy Policy 
  >>> SIGN UP!  
  Lost Password? 

Option Explicit
By: Developer Shed
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating:  stars stars stars stars stars / 0

    Table of Contents:

    Rate this Article: Poor Best 
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article




    by: Codefixer.com

    Option Explicit

    When writing your ASP pages, there is one very important step many developers unfortunately forget to do or in some cases are too lazy to do. Always put the effort in and avoid writing sloppy code, use Option Explicit.

    Option Explicit requires that all variable names be declared (with the Dim statement). It is good to declare your variables for a number of reasons. First, let's look at this code example:

    MyName = "michael"

    As i have mispelt MyName and written MyNam nothing will be printed out, ASP will create a new variable MyNam and assign an empty string to it. If your code is long then finding this typing mistake can take you hours.Trust me!!

    Option Explicit 'Always, always, always!
    'declare your variables
    dim MyName
    MyNam = "Michael"

    Note that If you write the code in the style above using Option Explicit you will
    get an ASP error informing you that MyNam is undefined. You must first use the dim statement. Debugging becomes alot easier!

    Below is a section of code with an example of a spelling mistake. We have declared our variables but unfortunately mispelled one of our variables ie MyNam. Using Option Explicit the undefined variable will be picked up and the error message 'Variable is undefined' will be displayed. This can truely save you an awful lot of time when debugging your code.
    Just note that the Option Explicit must come before any html code.

    <% Option Explicit %>
    <title>Using Option Explicit</title>

    <body bgcolor="#FFFFFF" text="#000000">

    'declare your variables
    dim MyName, MyAddress, MyfootballTeam
    MyNam = "michael"
    MyAddress = "16 Marki Street"
    MyfootballTeam ="Spurs"


    The above code will produce this error message.

    To sum up, using Option Explicit forces you to declare all your variables before you use them. If you use a variable you haven't declared then an error will be generated much like the one in the example above.

    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Web Development Articles
    More By Developer Shed



    - On Page SEO for New Domains
    - Improve Your Site`s Speed
    - Safari Books Online Review
    - Creating an Estore From the Ground Up
    - Most Common SEO Mistakes Developers Make
    - Making the Most of Your Titles and Meta Desc...
    - Five Ways Using Flash Can Damage Your Site
    - A Web Designer`s Guide to Colors
    - Use Webstarts to Create a Free Site
    - More Than Just Looks. How Your Web Design C...
    - How to Design Content Pages
    - Mint Review
    - Make Your WordPress Website Look Professional
    - How to Create a Mobile Web Site
    - Meta Tags: Still Useful?

    Developer Shed Affiliates


    © 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap