Is Option Explicit needed? (1 Viewer)

819 Ag

Registered User.
Local time
Today, 04:18
Joined
Mar 5, 2002
Messages
24
Friends,

I was checking out the Performance Analyzer in Access and it gave me a recommendation of using Option Explicit.

Is this needed and what benefit will it give me?


Thanks.
 

Peter D

Registered User.
Local time
Today, 04:18
Joined
Sep 7, 2000
Messages
188
YES!

Don't code without it.

Option Explicit makes sure that any variable that you use must be defined (ex.: with a "dim" statement).

If you don't explicitly declare your variables, you may mis-type the name of one somewhere in your code, it will compile just fine, but you will get unexpected errors.

You open yourself to more potential problems without Option Explicit.

Hope this helps,

Peter De Baets
Peter's Software - MS Access Tools for Developers http://www.peterssoftware.com
 

819 Ag

Registered User.
Local time
Today, 04:18
Joined
Mar 5, 2002
Messages
24
Thanks Peter.

I am assuming you put it at the top of the module under Option Compare Database.

Is this correct?
 

doulostheou

Registered User.
Local time
Yesterday, 22:18
Joined
Feb 8, 2002
Messages
314
I code in both 97 and 2000 at two different jobs. I've noticed that 2000 quit putting Option Explicit as a default item on each module page. I just assumed that it wasn't necessary in 2000. Was that assumption incorrect?
 

skiphooper

Registered User.
Local time
Yesterday, 23:18
Joined
Nov 29, 2000
Messages
76
Hi ,

If Option Explicit is not being entered by default.
open a module
click tools, go to options
under editor there is a line which says:
Require Variable Declaration

Make sure the ckeckbox is checked
Option Explicit will then be the default

HTH

Skip

[This message has been edited by skiphooper (edited 05-06-2002).]
 

shacket

Registered User.
Local time
Today, 04:18
Joined
Dec 19, 2000
Messages
218
I rather like not having to declare variables before assigning values. Other programming languages (i.e. Javascript) don't require the declaration.

Is there any other reason other than a typo that you would want to force yourself to add a line of code (i.e. a "dim" statement) for every variable you want to use?
 

Fornatian

Dim Person
Local time
Today, 04:18
Joined
Sep 1, 2000
Messages
1,396
If you don't declare your variables before you use them, they are self declared as being of type variant, this is the most memory intensive.

I always use Option Explicit.
 

Users who are viewing this thread

Top Bottom