Skip to main content

Posts

Showing posts with the label Option Explicit

Option Explicit

Option Explicit: Why we need this statement while writing VBScript? -- By default, VBScript will allow use of variables without declaration which leads to lot of mis-spell, type and wrong variable name errors. -- This will force the VBScript Engine not to accept the variables without declaration before its first use. -- Normally, Used to avoid typo errors, giving wrong variable names, redefining variables by mistake, etc. Consider the below script: Dim  var1 var1 =  10 'This line will not throw any error like "Variable undefined" var2 =  20 'This line will not throw any error like "Variable redefined" Dim  var1 After inserting Option Explicit Statement, it will throw error. Option   Explicit Dim  var1 var1 =  10 var2 =  20       'This line will throw error "Variable undefined" Also, Option   Explicit Dim  var1 var1 =  10 Dim  var1   ...