Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Option Explicit Statement from Visual Basic 6.0

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 28-11-2009
Member
 
Join Date: Jan 2009
Posts: 69
Option Explicit Statement from Visual Basic 6.0
  

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.

Reply With Quote
  #2  
Old 28-11-2009
Member
 
Join Date: May 2008
Posts: 2,001
Re: Option Explicit Statement from Visual Basic 6.0

HI, Basically Option Explicit Statement Forces explicit declaration of all variables in a file. It has following syntax:
Code:
Option Explicit { On | Off }
On - It is Optional. It enables Option Explicit checking. Bydefault it is on.
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.
Reply With Quote
  #3  
Old 28-11-2009
Member
 
Join Date: Apr 2008
Posts: 1,993
Re: Option Explicit Statement from Visual Basic 6.0

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.
Reply With Quote
  #4  
Old 28-11-2009
Member
 
Join Date: May 2008
Posts: 2,283
Re: Option Explicit Statement from Visual Basic 6.0

Hi, use of Option Explicit in you code forces explicit declaration of all variables in a file. It has following syntax:
Code:
Option Explicit { On | Off }
You can get some more clear information with the use of following example. c

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
Reply With Quote
  #5  
Old 28-11-2009
Member
 
Join Date: Oct 2005
Posts: 2,385
Re: Option Explicit Statement from Visual Basic 6.0

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.
Code:
 Private Sub Command1_Click()
    Dim one As String
    oone = "Hello"  
    MsgBox one
    End Sub
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Option Explicit Statement from Visual Basic 6.0"
Thread Thread Starter Forum Replies Last Post
How to write a SQL statement in Visual Basic? - Empty Shell - Software Development 4 27-02-2010 02:54 AM
Visual Basic 2008 error "Option Strict On disallows implicit conversions" Caiden Software Development 3 30-10-2009 06:27 PM
what are Visual Basic IDE? Naresh Modi Software Development 2 06-03-2009 08:49 AM
Is GUI same like Visual Basic ? Caesar Software Development 2 02-03-2009 12:32 PM
Visual Basic 2005 or Visual Basic 6 Aasha Software Development 5 15-01-2009 05:56 PM


All times are GMT +5.5. The time now is 06:59 PM.