Re: option explicit

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



And an example of why it's important.

Ctr_1 = Ctr_l + 1
looks like it should update ctr_1. But the right hand side uses ctr_L (ell, not
one). So if you had forced yourself to delclare your variables with "Option
Explicit", it might be moments of debugging time instead of hours.

And one more reason I like it is that when I declare an object explicitly:

Dim Wks as worksheet

I get VBA's intellisense to help out when I'm writing the code.

wks.
As soon as I hit that dot, I get a list of properties and methods that could
come next.

And one more reason.

If I declare a variable like:

dim myWksThatShowsTheSummary as Worksheet

I can type mywks and hit ctrl space bar to have the VBE autocomplete (or show me
possible matches) that variable. And I know that when I finish coding that
statement, the VBE will match my upper/lower case in the Dim statement.

If the variable stays lower case, I know I made a typo.

Dave F wrote:

Hi,

Two quick questions about 'option explicit.'

1) What does it do?

2) How do I configure VBE to automatically set option explicit?

I know it has something to do with declaring variables, but I don't know why
it's important. Thanks,

Dave
--
Brevity is the soul of wit.

--

Dave Peterson
.



Relevant Pages

  • Re: Need some general Tips and Tricks for programming !
    ... And make sure you force yourself to declare your variables. ... Saved from an earlier post about why "option explicit" should be used. ... If I add "Option Explicit" to the top of a module (or have the VBE do it ... Dim wks as worksheet ...
    (microsoft.public.excel.programming)
  • Re: Need some general Tips and Tricks for programming !
    ... If you must use persistent variables, maybe you can create a routine that ... And make sure you force yourself to declare your variables. ... If I add "Option Explicit" to the top of a module (or have the VBE do it for me ... Dim wks as worksheet ...
    (microsoft.public.excel.programming)
  • Re: disable print
    ... Inside the VBE ... If I add "Option Explicit" to the top of a module (or have the VBE do it for me ... Dim wks as worksheet ... From what I've read, if you declare a variable as Integer, the modern pc ...
    (microsoft.public.excel.misc)
  • Re: disable print
    ... Inside the VBE ... Dim wks as worksheet ... From what I've read, if you declare a variable as Integer, the modern pc ... "Dave Peterson" wrote: ...
    (microsoft.public.excel.misc)
  • Re: Querying a database
    ... Use My Database ... Declare @sCnt VarChar ... Set Nocount Off ... Dim pairsAdapter As New MWFNTableAdapters.MWFNTableAdapter ...
    (microsoft.public.vb.database)