Declaring variables using option explicitWe use the line Option Explicit at the top of the page. The purpose of writing this line is tell the ASP engine that the variables we will be using in this page are to be declared before being used. For example if we are using a variable as v1 then before assigning any value to this variable we must declare v1 as a variable.
If we remove the line Dim v1 from above code then we will get error message as before that we have told ASP engine that we will be declaring the variable before using. So the complete code for above this would be.
This is how we will declare variables before using and we got the option of not using the line Option Explicit at the top of the page and use the variables without declaring. Then the question is why we need this Option Explicit and then declare the variable? The main reason is for bigger pages we may do some spelling mistakes in using variables and get undesirable results which are difficult to debug. For example let us see the code below where Options explicit is not used.
You can see in the above code Value of variable v1 is not printed to screen as we have wrongly used it as v ( in place of v1). Imagine such mistakes in pages where hundreds of lines are used. Here no error message is printed so difficult to indentify where the problem is.
This article is written by plus2net.com team.
Be the first to post comment on this article :