DIAdem Help

Explicit Statement Option

  • Updated2024-09-12
  • 1 minute(s) read

Explicit Statement Option

In VBS you can use undeclared variables by including the variable names anywhere in the script. As soon as VBS finds an undeclared variable, it creates storage space for the variable. The disadvantage is that VBS does not recognize incorrect variable names, which can lead to unexpected results when the script is executed.

To prevent this program behavior, use the Option Explicit statement, which forces the explicit declaration of all variables. The Option Explicit statement should always be the first statement in a script.

The following example returns an error message because the variable A is not declared. Change A to rA in the third row for this example to work without errors.

Option Explicit
Dim rA, rB, rResult
A = 3
rB = 5
rResult = rA + rB
Call MsgBox(rResult)