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!
Printable View
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!
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.
You really are supposed to use it, yeah.
It's a security for typos... because when you type
It basicly checks if you declared any variable, if not you'll get warned...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'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.
Hey Jop, obviously your 'Do something wil include incrementing intT ;-)
td.
Good thinking T.D. :)
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
You can also let VB automaticly add it to any form/module/etc.
click Tools > Options > and check Require variable Declaration
Thanks!
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"
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.
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.
yeah, that's what I said (gamma) hehe sorry dutch joke ;)
sorry I'm in a childish mood...