question on scope of a variable

C

Chip Orange

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
 
W

Word Heretic

G'day "Chip Orange" <[email protected]>,

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:
 
C

Chip Orange

Word Heretic said:
G'day "Chip Orange" <[email protected]>,

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:

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
 
W

Word Heretic

G'day "Chip Orange said:
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:
 
C

Chip Orange

Word Heretic said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top