שתף באמצעות


Difference between Option Explicit and Option Strict

Question

Tuesday, May 17, 2005 9:10 AM

What is difference between Difference between Option Explicit and Option ?

All replies (2)

Tuesday, May 17, 2005 10:56 AM ✅Answered | 1 vote

Hi,

Option Explicit is to do with variable declaration and Strict is for type conversions.

Option Explicit:
When Option Explicit appears in a file, you must explicitly declare all variables using the Dim, Private, Public, or ReDim statements. If you attempt to use an undeclared variable name, an error occurs at compile time.

Option Strict:
Visual Basic .NET generally allows implicit conversions of any data type to any other data type. Data loss can occur when the value of one data type is converted to a data type with less precision or smaller capacity, however, a run-time error message will occur if data will be lost in such a conversion. Option Strict ensures compile-time notification of these types of conversions so they may be avoided.

Regards,
Vikram


Tuesday, May 17, 2005 5:45 PM ✅Answered

Two different animals.

Option Explicit is in regards to you being required to explicitly declare your variables (instead of just typing a name and assigning a value to it resulting in an implicit declaration).  So you've gotta declare your variables using Dim, Private, Public, or ReDim statements.

Option Strict disallows automatic conversions of a data type to another data type where you could potentially lose data. (see the msdn entry on this).

Tom