Results 1 to 12 of 12

Thread: Option Explicit?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    HI,

    I was wondering. I know Option Explicit
    is something you are suppose to use but
    I never use it! So Why should I use it
    and how would it help me? Thanks!

  2. #2
    Lively Member
    Join Date
    Aug 2000
    Location
    Texas
    Posts
    88
    There is nothing wrong if you don't use it in your program, but it is pretty useful when you write a big program because if you use this option, you will have to declare all of variables before using it. Therefore, it's easy when you want to dedug the program.

  3. #3
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    You really are supposed to use it, yeah.

    It's a security for typos... because when you type

    Code:
    Dim intT%
    
    Do While int < 5 'note the int instead of intT
    'do something
    Loop
    
    It'll end in a endless loop
    When you used Option Explicit you'll got an error...
    It basicly checks if you declared any variable, if not you'll get warned...

    It's also usefull to prevent from 'forgetting' do declare variables (which makes them variants, and they're memory consuming)


    ... so it's a good thing to use it.
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  4. #4
    Hyperactive Member tumblingdown's Avatar
    Join Date
    Mar 2000
    Posts
    362
    Hey Jop, obviously your 'Do something wil include incrementing intT ;-)


    td.
    "One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig


    [email protected]

    "but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.

  5. #5
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Good thinking T.D.
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    Thanks!

    You wouldnt believe what happened in
    my project when I put 'Option Explicit'
    in all the modules and forms!
    It took almost 10 minutes to fix all of
    the errors! Thanks alot!

    Evan

  7. #7
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    You can also let VB automaticly add it to any form/module/etc.

    click Tools > Options > and check Require variable Declaration
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    Thanks!

  9. #9
    New Member
    Join Date
    Nov 2000
    Location
    Seattle
    Posts
    1

    Wink Option Explicit

    As i understand that option explicit is basically a variable case spell checker.
    for example:

    Option Explicit
    Dim MyName as String
    __________________________

    Public Sub PrintName_Click()
    'If you type

    myname = "Trinity"

    'it will change it to....

    MyName = "Trinity"


  10. #10
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Nope, not really, that's already done in VB automaticly.

    it just checks if the variable is declared somewhere.

    Like

    Dim intT%

    and int < doesn't exists so gives an error, try for yourself.
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  11. #11
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736

    Also

    Straight out of MSDN.

    If you don't use the Option Explicit statement, all undeclared variables are of Variant type unless the default type is otherwise specified with a Deftype statement.


  12. #12
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    yeah, that's what I said (gamma) hehe sorry dutch joke
    sorry I'm in a childish mood...
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width