Results 1 to 6 of 6

Thread: option explicit

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    East Providence, RI
    Posts
    1,715
    I always use option explicit, but what exatly does it do? I forgot where but it said that I should but Option Explicit in the declerations section, but I'm just wondering what does it do?
    NXSupport - Your one-stop source for computer help

  2. #2
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    It makes you so you have to Dim your varibles and if you don't it gives you an Ambiguous name error.

  3. #3
    Guest
    Look in your VB Help file for Option Explicit statement.

    Here is what it says (if you don't have a help file):

    Option Explicit Statement

    Used at module level to force explicit declaration of all variables in that module.

    Syntax

    Option Explicit

    Remarks

    If used, the Option Explicit statement must appear in a module before any statements that declare variables or define constants.
    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.
    When you use the Option Explicit statement, you must explicitly declare all variables using the Dim, Private, Public, ReDim, or Static statements. If you attempt to use an undeclared variable name, an error occurs at compile time.

    Tip Use Option Explicit to avoid incorrectly typing the name of an existing variable or to avoid risking confusion in code where the scope of the variable is not clear.

  4. #4
    Fanatic Member
    Join Date
    Jun 1999
    Location
    California, USA
    Posts
    662
    It makes vb require that you Dim a variable before you could use it:

    Code:
    Option Explicit
    
    Sub Test()
        For i = 1 To 10
            DoSomething
        Next i
    End Sub
    would cause a "Variable not defined" error

    to fix it:
    Code:
    Option Explicit
    
    Sub Test()
        Dim i%
        For i = 1 To 10
            DoSomething
        Next i
    End Sub

  5. #5
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    Why do people not read the previous posts?

  6. #6
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840

    Talking

    Sometimes because it hasn't appeared yet (being written at the same time)

    but mostly because of a short attention span and a desire to get to the bottom of the thread

    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

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