Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Adelisa Fischer   on Sep 01 In MS Office Category.

  
Question Answered By: Ray Lawrence   on Sep 01

If you declare  the variable  in more than one module  you will get two
separate variables, and confusion will reign. :-)

Global variables  are only declared once. If they are declared in a normal
module, they will retain  their values  during execution of the VBA program.
However, they are not saved - they are simply global variables.

It is extremely important that you have Option Explicit at the top of every
module to ensure that you are not inadvertently creating more than one
variable with very similar names.

You should also use "dot" notation to refer to public  variables in other
modules, to ensure that both you and VBA are in agreement on what you're
talking about. E.g. if ResponseQPI is declared in module Fred, then you
should refer to it as Fred.ResponseQPI.

Within the module that has ResponseQPI declared in it, it is optional
whether you use dot notation or not. I do not.

You need to make sure that you really are declaring public variables too.
I.e. the declaration has the word Public in it, and the declaration is at
the top of the module - after the Option Explicit, but before any
subroutines or functions.

Last, but definitely not least ... look for a logic error. vbYes has a
value of 6 and vbNo has a value of 7. When created, your byte  variable will
have a value of zero. The only way it can become vbYes is if it is set  that
way.

But look at how you're checking the variables. A check for <> vbNo is
incorrect as a check for "yes". This is not a Boolean variable.

Share: 

 

This Question has 3 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Public variables Or get search suggestion and latest updates.


Tagged: