Groups | Blog | Home
all groups > vb.net > may 2004 >

vb.net : What does this do?Option Explicit?


ken
5/31/2004 11:36:01 PM
hi All

What does this command dot

BluDog
6/1/2004 8:11:51 AM
[quoted text, click to view]

It ensures all variables are declared before you can use them.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vastmOptionExplicit.asp

Cheers

limint
6/1/2004 9:05:16 AM

"ken" <anonymous@discussions.microsoft.com> a écrit dans le message de
news:CC22D1CB-23E7-4B64-A0F8-31AAA8A29921@microsoft.com...
[quoted text, click to view]

When you specify Option Explicit on, you are obliged to declare all your
variables before using them.

Arne Janning
6/1/2004 9:13:01 AM
[quoted text, click to view]

Hi ken,

Option Explicit means that you have to declare your variables before you
can use them.

Option Explicit On

Private Sub Button1_Click(...) Handles Button1.Click
i = 1
End Sub

--> Compiler Error. You have to declare i first: Dim i as Integer


Option Explicit Off

Private Sub Button1_Click(...) Handles Button1.Click
i = 1
End Sub

--> no compiler error.

There is only one thing to say about Option Explicit Off: do not use it.

It makes your code less safe and errors will be hard to detect.

Cheers

Armin Zingler
6/1/2004 1:02:27 PM
"ken" <anonymous@discussions.microsoft.com> schrieb
[quoted text, click to view]

http://msdn.microsoft.com/library/en-us/vblr7/html/vastmOptionExplicit.asp


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
hirf-spam-me-here NO[at]SPAM gmx.at
6/1/2004 2:58:28 PM
* =?Utf-8?B?a2Vu?= <anonymous@discussions.microsoft.com> scripsit:
[quoted text, click to view]

Place the caret on 'Option Explicit' and press the F1 key.

--
Herfried K. Wagner [MVP]
AddThis Social Bookmark Button