|
-
Aug 21st, 2000, 05:42 PM
#1
Thread Starter
Frenzied Member
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
-
Aug 21st, 2000, 05:46 PM
#2
So Unbanned
It makes you so you have to Dim your varibles and if you don't it gives you an Ambiguous name error.
-
Aug 21st, 2000, 05:56 PM
#3
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.
-
Aug 21st, 2000, 06:03 PM
#4
Fanatic Member
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
-
Aug 21st, 2000, 06:06 PM
#5
So Unbanned
Why do people not read the previous posts?
-
Aug 21st, 2000, 09:51 PM
#6
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|