Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Implicit vs Explicit 1

Status
Not open for further replies.

RebelFox

Programmer
Jun 16, 2002
62
GB
Could somebody explain to me the difference between an implicit variable definition and an explicit variable definition?
 
Implicit declaration isn't good practice. It allows you not to dim variables in advance and just introduce them as and when necessary in the code. The disadvantages are:

- They will be Variant data type which occupies 16 bytes and is wasteful.

- It's easy to mistype a variable name later in the code. It won't cause any compile errors but will have a value of Empty at run-time, when you are expecting the value in the correctly spelt variable

I would always use Option Explicit to force explicit declaration. It leads to many good coding practices such as declaring all variables at the start of the procedure, prefixing the variable name to identify the data type and commenting the purpose of the variable.

Option Explicit provides compile-time checking for mistyped names and data type mismatches.

Paul Bent
Northwind IT Systems
 
I see. Explicit is using a Dim to specify the variable type while implicit is a variable without a Dim specification that the process allocates as a variant.

Many thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top