Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 08-07-2013, 07:11 AM   #1
TJPoorman
Newly Registered User
 
Join Date: Jul 2013
Posts: 402
Thanks: 0
Thanked 135 Times in 131 Posts
TJPoorman is on a distinguished road
How to use Variable Declaration to narrow down problems

In order to help us to narrow down some of your problems please turn on variable declaration in your VBA project. Please see the attached pictures on how to turn this on.

Thank you
Attached Images
File Type: png 1.png (24.3 KB, 1239 views)
File Type: png 2.PNG (24.2 KB, 1164 views)

TJPoorman is offline   Reply With Quote
The Following 2 Users Say Thank You to TJPoorman For This Useful Post:
hassanogaibi (06-28-2016), mrheffner (07-29-2019)
Old 08-26-2014, 01:41 AM   #2
max1
Newly Registered User
 
Join Date: Jun 2014
Location: Perth, Western Australia
Posts: 30
Thanks: 4
Thanked 1 Time in 1 Post
max1 is on a distinguished road
Re: How to use Variable Declaration to narrow down problems

What is the difference between this and 'Option Explicit' ?
max1 is offline   Reply With Quote
The Following User Says Thank You to max1 For This Useful Post:
hassanogaibi (06-28-2016)
Old 08-26-2014, 02:31 PM   #3
Galaxiom
Super Moderator
 
Join Date: Jan 2009
Location: NSW Australia
Posts: 11,558
Thanks: 88
Thanked 1,477 Times in 1,394 Posts
Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold Galaxiom is a splendid one to behold
Re: How to use Variable Declaration to narrow down problems

Quote:
Originally Posted by max1 View Post
What is the difference between this and 'Option Explicit' ?

The setting automatically adds Option Explicit to all new modules.

Galaxiom is offline   Reply With Quote
The Following User Says Thank You to Galaxiom For This Useful Post:
hassanogaibi (06-28-2016)
Old 08-05-2015, 04:43 AM   #4
rbh1090
Newly Registered User
 
Join Date: Aug 2015
Posts: 18
Thanks: 0
Thanked 1 Time in 1 Post
rbh1090 is on a distinguished road
Re: How to use Variable Declaration to narrow down problems

Declaring a variable is the first step to achieve an efficient and error-free code. To use an incorrect type of variable involves consuming more memory and processing time than the necessary.

Variables can be declared in two ways: Implicitly and Explicitly. Unless Option Explicit, is indicated all the variables of the module are implicit, that is, they do not have a defined scope (private, public, static) and they are of the Variant type, (they are not associated to an specific type: numeric, text, date, etc.)

Using implicit variables may lead to run time errors: suppose that in a part of the process variable XYZ = "123" is declared and then in other part of the same process a reference is erroneously made to the same variable like XZY = "456". This will create a new variable rather than changing its value without any warning and as a result, an execution error occurs.

In addition, the "Variant" type require more space in the memory. For example, to store an integer in a Variant type 128 bits are needed while storing the same value in an integer will only need 16 bits. However, there are occasions in which this type of variables should be used: the most common example is to assign a null value to a variable, only “Variant” types accept null values.

Practically the only advantage of using implicit variables is that it allows the elimination of a few code lines.

In short, the variables must be explicitly declared. Perhaps the only valid scenario for the implicit variables is during the development stage while designing a process.

rbh1090 is offline   Reply With Quote
The Following User Says Thank You to rbh1090 For This Useful Post:
hassanogaibi (06-28-2016)
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Static variable declaration breaks editor grinnZ Modules & VBA 3 06-29-2011 08:10 AM
Type Variable Declaration Galaxiom Modules & VBA 2 12-23-2009 06:26 PM
Need to narrow a query & report down jlb Queries 6 10-17-2008 08:54 PM
Variable Declaration paulmcdonnell Modules & VBA 2 03-17-2004 06:02 AM
how can I narrow this code down? JonatABS General 12 08-06-2003 06:20 PM




All times are GMT -8. The time now is 06:37 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World