Home  >  Article  >  The option explicit statement cannot be placed in

The option explicit statement cannot be placed in

(*-*)浩
(*-*)浩Original
2019-07-25 13:05:143793browse

The Option Explicit statement is used at the module level to force explicit declaration of all variables in the module.

The option explicit statement cannot be placed in

Option Explicit statement cannot be placed in any event procedure. Option Explicit statements must be written before all procedures in the module. (Recommended learning: PHP video tutorial)

If Option Explicit is used in the module, you must use the Dim, Private, Public, ReDim or Static statement to explicitly declare all variable.

If an undeclared variable name is used, an error will occur during compilation.

If the Option Explicit statement is not used, all undeclared variables are of type Variant unless a default type is specified using the Deftype statement.

Note: Use Option Explicit to avoid misspellings when typing existing variables. Use this statement in code where the scope of the variable is not very clear to avoid confusion.

The method to automatically add Option Explicit in VB is: select the "Options" command in the "Tools" menu, open the "Options" dialog box, click the "Editor" tab, and select the "Require variable declaration" option

The default setting of the compiler will be Option Explicit On.

This example uses the Option Explicit statement to force explicit declaration of all variables. Attempting to use an undeclared variable will result in a compilation error. The Option Explicit statement is only used at the module level.

Option Explicit ' Force explicit variable declaration.
Dim MyVar As Integer ' Declare variable.
MyInt = 10 ' Undeclared variable generates error.
MyVar = 10 ' Declared variable does not generate error.
说通俗点,就是为了避免混乱,使用 Option Explicit 之后,必须对变量进行声明才可以使用!
举个简单的例子:
<script language="vbscript">
< !--
Option Explicit \&#39; 要求在脚本中声明所有的变量
Dim Mystring
Mystring="This is my string"
-- >
< /script>

For more PHP related technical articles, please visit the PHP Graphic Tutorial column to learn!

The above is the detailed content of The option explicit statement cannot be placed in. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn