What is the reason that many of the programers uses the Option Explicit statement into the Visual Basic 6.0? Can anyone has the details about it? Please help me about this? I am waiting for your reply.
What is the reason that many of the programers uses the Option Explicit statement into the Visual Basic 6.0? Can anyone has the details about it? Please help me about this? I am waiting for your reply.
HI, Basically Option Explicit Statement Forces explicit declaration of all variables in a file. It has following syntax:
On - It is Optional. It enables Option Explicit checking. Bydefault it is on.Code:Option Explicit { On | Off }
Off - It is also Optional. It is used to disable Option Explicit checking.
To set Option Explicit in the integrated development environment (IDE) follow the following steps:
- On the Tools menu, choose Options.
- Open the Projects and Solutions node.
- Choose VB Defaults.
- Modify the Option Explicit setting.
Hi, if you are using Option Explicit statement in your source code then it must appear in a file before any other source code statements. When Option Explicit appears in a file, you must explicitly declare all variables using the Dim or ReDim statements. If you attempt to use an undeclared variable name, an error occurs at compile time. So basically Option Explicit is used to avoid incorrectly typing the name of an existing variable or to avoid confusion in code where the scope of the variable is not clear. The compiler bydefault sets Option Explicit On, if you don't specify Option Explicit in your code. But, it is a good programming practice to use the option explicit in your code. So, try to use it into your code.
Hi, use of Option Explicit in you code forces explicit declaration of all variables in a file. It has following syntax:
You can get some more clear information with the use of following example. cCode:Option Explicit { On | Off }
Code:' Force explicit variable declaration. Option Explicit On Dim variable As Integer variable = 588 ' The following assignment produces a COMPILER ERROR because ' the variable is not declared and Option Explicit is On. number = 10 ' will causes ERROR
Hi, you will see the Option Explicit statement at the top of VB code.This statement forces you to declare your variables before you use them. Just simple. By placing Option Explicit at the top of every code module before any procedures you will become safe regarding not the use of any variable without declaration. For example.
This code will give you a blank message box. Due to the wrong use of the variable. Now if you used the Option Explicit at the top of the code, you get a "Variable not defined" error. This is a simple fix for what could be a complex problem. It also increase your speed of code execution.Code:Private Sub Command1_Click() Dim one As String oone = "Hello" MsgBox one End Sub
Bookmarks