PDA

Click to See Complete Forum and Search --> : Option Explicit


PITBULLCJR
Jan 20th, 2000, 02:16 AM
What exactly does this do. I have found in some programs I needed it and in others if I do use it it crashes. Like for instance I can't get this code to work if I put in option Explicit

Sub Timeout(duration)
starttime = Timer
Do While Timer - starttime < duration: DoEvents
Loop
End Sub

Private Sub Command1_Click()
Timeout (10)
Label1.Caption = "hello"
End Sub


------------------
Sincerely,
Chris
:-) ;-)
Email pitbullcr7@aol.com

Aaron Young
Jan 20th, 2000, 02:21 AM
Option Explicit makes sure that any Vairables you use are Pre-Defined, otherwise it'll give you an Error Message telling you it isn't.

It's useful for making sure you keep your Programs Tidy, it can also help if you make a Typo with a Vairable name.

If you don't use Option Explicit VB doesn't care if you create variables on the fly, i.e

A = 1

Instead of:

Dim A As Integer
A = 1

------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
ajyoung@pressenter.com

JSexton
Jan 20th, 2000, 02:27 AM
PITBULLCR,

Your program works.

Option Explicit forces you to declare all variables in a module.

If you don't use option explicit, all undeclared variables are variant types.

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

Joe

MartinLiss
Jan 20th, 2000, 03:08 AM
I would suggest you change your project properties so that you always use Option Expicit. Without it you might spend a lot of time figuring out why the following code never ends. Dim MyMispelledValue As Integer

While MyMispelledValue < 100
' do something
MyMispelledValue = MyMisspelledValue + 1
Wend


------------------
Marty
Can you buy an entire chess set in a pawn shop?

ZanM
Jan 20th, 2000, 09:22 AM
also if you don't use option explicit and all you variables are variant your program could compile significantly larger than if you declare strings, longs,.....

------------------
SomeTimes Coffee Just Isn't Enough.
Zan Magi