Option Explicit:
The Option Explicit statement forces the explicit declaration of all variables using the Dim, Private, Public, or ReDim statements.
This statement prevents the accidental reuse of the name of a previously declared variable. Also, if you mistype a declared variable's name or try to use an undeclared variable, an error message is generated.
Note that the Option Explicit statement must be placed at the top of the code before any other VBScript commands
Ex: Option Explicit
Dim a,b,c
a = 10
b = 20
c = a+b
VBScript ingeneral doesn't need variable declaration. For example without using "Dim" a variable can be directly used for assigning etc.
For ex: temp=1
However, such practise can always be error prone. Ex: if i want to use the same variable in someother statement and miss spell it,say
tempe=temp+1
VBScript still considers "tempe" as valid. This case if we use OPTION EXPLICIT On top of our application and proceed then application will not proceed unless until u declare each and every variable. Hence u make sure that ur variable is serving ur purpose.
The Option Explicit statement forces the explicit declaration of all variables using the Dim, Private, Public, or ReDim statements.
This statement prevents the accidental reuse of the name of a previously declared variable. Also, if you mistype a declared variable's name or try to use an undeclared variable, an error message is generated.
Note that the Option Explicit statement must be placed at the top of the code before any other VBScript commands
Ex: Option Explicit
Dim a,b,c
a = 10
b = 20
c = a+b
VBScript ingeneral doesn't need variable declaration. For example without using "Dim" a variable can be directly used for assigning etc.
For ex: temp=1
However, such practise can always be error prone. Ex: if i want to use the same variable in someother statement and miss spell it,say
tempe=temp+1
VBScript still considers "tempe" as valid. This case if we use OPTION EXPLICIT On top of our application and proceed then application will not proceed unless until u declare each and every variable. Hence u make sure that ur variable is serving ur purpose.
No comments:
Post a Comment