Get the App
SLTechnology News&Howtos  ›  Development  › 

What is an Option Explicit statement

Shulou Source: shulou.com Published: 2022-06-03 08:37:47 09月30日 Update

This article mainly explains "what is the Option Explicit sentence". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the Option Explicit sentence"?

Forces all variables in the script to be explicitly declared.

Option Explicit

Description

If you use Option Explicit, this statement must appear before any other statements in the script.

When using Option Explicit statements, you must explicitly declare all variables using Dim, Private, Public, or ReDim statements. If you try to use an undeclared variable name, an error will occur.

Tips: you can use Option Explicit to avoid misspelling existing variable names. For variables whose scope of action is not clear, using this sentence can avoid confusion.

The following example illustrates how to use the Option Explicit statement:

Option Explicit 'forces the declaration variable to be displayed. Dim MyVar 'declares variables. MyInt = 10 'undeclared variable produces an error. MyVar = 10 'declares that variables do not produce errors. Thank you for your reading, the above is the content of "what is the Option Explicit sentence", after the study of this article, I believe you have a deeper understanding of what is the Option Explicit statement, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Statements variables errors learning content scripts compulsion clarity function examples names that is ideas situations articles more unpassed knowledge knowledge points articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Shulou Information Linux MariaDB Xiaomi