Home >Common Problem >What does option explicit do?
option The function of explicit is to declare that all variables need to be defined before they can be used. Otherwise, the program will report an error when using undefined variables. In this way, errors caused by variable name spelling and other errors can be avoided. .
VBScript does not require explicit definition of variables, that is, variables can be used directly without definition. This is very convenient, but it is also prone to problems;
For example, first define a variable named "var9" and assign a value, but when using it below, the variable name is mistakenly written as "varg", as shown in the code below. In this way, no exception will occur when the program is executed, but This will cause the processing results to be inconsistent with expectations. We expected to use msgbox to output the value of var9, but the value of varg was output, and var9 has not been assigned a value and defaults to a null value;
The execution result is:
The "Option Explicit" we are going to talk about can solve the above problem. The function of "Option Explicit" is: to declare all variables, they need to be defined first can be used, otherwise the program will report an error when using undefined variables. In this way, you can avoid errors caused by variable name spelling and other errors, and "Option Explicit" can speed up the running speed of the program. It saves The time to dynamically allocate variable storage space when the program is running;
We use the code just now to fine-tune it, and add "Option Explicit" to see the effect:
The execution result is:
The program reported an error and identified the problem with our use of variables. Therefore, when programming, it is better to add "Option Explicit" to prevent unnecessary exceptions. It is worth noting: "Option Explicit” must be placed at the top of the program.
The above is the detailed content of What does option explicit do?. For more information, please follow other related articles on the PHP Chinese website!