Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / January 2005

Tip: Looking for answers? Try searching our database.

question on scope of a variable

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chip Orange - 15 Dec 2004 20:18 GMT
I've tried declaring a public variable in a module of my project in hope
that it can be accessible by any of the forms; I mean that I'd like a form
to be able to initialize it, or have access to it's value if it's
initialized by a routine in the modules section.

While this compiles for me, I'm getting a runtime error that indicates the
object variable isn't initialized when accessed by a form, but declared and
initialized by a module.

If I add a second initialization statement in the form itself then all runs
ok.

I obviously don't understand the scoping rules here, so could someone
explain to me if it's possible to have a variable accessible everywhere
(that is, have it be static?).

I did try declaring it using the STATIC command in the module but the
compiler wouldn't allow that.

thanks.

Chip
Word Heretic - 16 Dec 2004 04:19 GMT
G'day "Chip Orange" <Chip.Orange@psc.state.fl.us>,

Accessible everywhere is not Static.

If I have a std code module and declare at the top of it, outside of
any sub

Public ICanSeeThisEverywhere as Variant

then that should be accessible to your form.

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice

Chip Orange reckoned:

>I've tried declaring a public variable in a module of my project in hope
>that it can be accessible by any of the forms; I mean that I'd like a form
[quoted text clipped - 18 lines]
>
>Chip
Chip Orange - 16 Dec 2004 16:52 GMT
> G'day "Chip Orange" <Chip.Orange@psc.state.fl.us>,
>
[quoted text clipped - 36 lines]
> >
> >Chip

Yes, it is, but it seems to have a lifetime which I don't understand, and at
the end of it's lifetime, it's value is being reset to "nothing", so while
some form or routine can "see" it, it has no useful data.

Some of these routines I'm speaking of are called from custom menus, so the
user is returned to Word in between the calls to various forms or routines
they initiate by a menu choice.

hope that makes things clearer.

thanks.

Chip
Word Heretic - 16 Dec 2004 22:18 GMT
G'day "Chip Orange" <Chip.Orange@psc.state.fl.us>,

> it's value is being reset to "nothing"

This happens if a runtime error causes a recompile. Might this be the
case?

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice

Chip Orange reckoned:

>> G'day "Chip Orange" <Chip.Orange@psc.state.fl.us>,
>>
[quoted text clipped - 54 lines]
>
>Chip
Chip Orange - 13 Jan 2005 21:56 GMT
> G'day "Chip Orange" <Chip.Orange@psc.state.fl.us>,
>
> > it's value is being reset to "nothing"
>
> This happens if a runtime error causes a recompile. Might this be the
> case?

It's certainly possible that a run-time error is happening, I trap many with
"on error" and continue; I didn't realize that would cause a recompile.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.