Re: scope of variables

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Jonathan West (jwest_at_mvps.org)
Date: 02/24/05


Date: Thu, 24 Feb 2005 15:22:15 -0000


"Jean-Guy Marcil" <no-spam@leaveme.alone> wrote in message
news:uDKecJoGFHA.3648@TK2MSFTNGP09.phx.gbl...
> Mark L was telling us:
> Mark L nous racontait que :
>
>> If I have VBA code in a Word document which is using a module, some
>> forms and ThisDocument (ie Document_Open and Document_Close), where
>> should I declare Public variables so that they are accessible to the
>> whole thing? In the past I would have declared such variables in the
>> Module declarations, but I think these are not being made available
>> to the ThisDocumant section of the code. Thank you for any help you
>> can give me. --
>> Mark L
>
> You cannot have public declarations in a class module (ThisDocument is a
> "special" class module).

That's not strictly true. You can have public declarations in a class
module, but they don't act as global variables, they act as public
read-write properties of the class.

>
> Create a module that you could call "PubVariables" and use it to declare
> those public variables.

That is the way to do it. Variables declared as Public and defined before
the first Sub or Function in a module will be available to all modules,
classes and UserForms within the same project.

-- 
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup


Relevant Pages

  • [PATCH] char: static functions and integer as NULL pointer fixes in epca.c
    ... Forward declarations were already marked static, ... More majordomo info at http://vger.kernel.org/majordomo-info.html ... Please read the FAQ at http://www.tux.org/lkml/ ...
    (Linux-Kernel)
  • Re: Problem in Strdup()
    ... > Mark B wrote: ... >> In general I also tend to seperate my declarations from the first ... >> code aesthetics ... stated that for me personally I separate declarations from ...
    (comp.lang.c)
  • Memory usage
    ... Is there any difference in memory footprint between the 2 following ... TIA, ... Mark ...
    (microsoft.public.dotnet.framework.compactframework)