|
-
Dec 30th, 2000, 08:34 AM
#1
Thread Starter
Fanatic Member
What does Option Explicit do? <-- That's my question! I've made so many big usefull programs with API and so much more but I never knew why I had to put Option Explicit at the top of every single one of them! Thanx in advance for your help!
Visual Basic 6.0
Visual C++ 5
Delphi 5

-
Dec 30th, 2000, 08:45 AM
#2
Fanatic Member
Adding Option Explicit to your app will raise an error if you try to use a variable that hasn't been declared.
For example...
Code:
Option Explicit
Private Sub Form_Load()
s = "HELLO WORLD" ' causes error to be raised because s is not declared
End Sub
Code:
Private Sub Form_Load()
s = "HELLO WORLD" ' works fine because Option Explicit is not used
End Sub
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
-
Dec 30th, 2000, 09:15 AM
#3
Thread Starter
Fanatic Member
Does it declare the variable if it's not declared! FOr Ex:
Code:
Option Explicit
Function OpenQ(OpL As String)
s = "hello" '<-- would that generate a variable called S
End IF
Visual Basic 6.0
Visual C++ 5
Delphi 5

-
Dec 30th, 2000, 09:18 AM
#4
Fanatic Member
Nope that code would cause an error because you didn't declare it, if you want to use variables in that way then you need to get rid of the Option Explicit statement.
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
-
Dec 30th, 2000, 09:26 AM
#5
If you don't use Option Explicit, it implicitly declares variant variables for you.
I would recommend to stick to the Option Explicit statement, because it warns you for unwanted variable declarations. A typo could be difficult to find, if no error is generated, but another variable is declared instead.
If you get tired of typing the Option Explicit statement, go to Tools --> Options and check the Require Variable Declaration checkbox. All new code modules will have the Option Explicit statement added automatically.
-
Dec 30th, 2000, 11:19 AM
#6
Member
I know theres someway you can make it so that option explicit is automatically there for very form you make, how do you do this?
Thanks
cram
[email protected]
_ _ _ _ _ _ _ _ _ _ _ _ _ _
Things to Ponder

|Man who stands on toilet,
Is high On pot|
|Baseball Wrong,
Man with four balls cannot walk|
-
Dec 30th, 2000, 11:57 AM
#7
Fanatic Member
Look at Frans C's post directly above yours.
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
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
|