about variables and subs

V

Vincent

I have a problem regarding subs; private, regular, public and static ones. A
practical problem. I cannot seem to transform theory into practise. Whenever
I try to find info on this, on help within the program, on online help, in
newsgroups, I find myself giving up – almost. So I write instead. Maybe there
are more people than I also having trouble on this subject …
I understand the difference between “Regular†sub’s and “Private†subs. This
both clear and evident when used. They have different scope – one only works
in a module, the other in the whole project. This becomes very evident, if
not before, when trying to name a sub with the same name – works perfectly
in a Private Sub, not so in a regular one (I know, I know – this is not what
I usually do. I don't use the same name for every sub I have – it was an
example…)
So far so good, it is then the trouble begins. For I can’t seem to
comprehend beyond that … I know there are other kinds of Sub’s. I know there
are “Public†ones and there are “Static†ones. I just can’t seem to make them
work!
I would like to for example place a Public or Static (dunno which, one of
them…) in for example an Autostart macro. In that macro, I would dim a number
of variables: name, special paths to certain directories and so on and so on…
After doing that, I would be able to access these variables from ANY
template. This I cannot to. Whenever I change/rename/create a directory, I
still have to edit each macro - manually. This is both time and labour
consuming. Not to mention – how tedious it is.
There should be something easier “out thereâ€

--
 
J

Jezebel

Not quite sure what you're asking here. Are you concerned about Subs or
about variables? Subs are public by default; the 'public' keyword is
optional, included only for consistency: all subs are public unless you
specifically make them private. (There's also the 'Friend' keyword, which
you've omitted from your collection: it makes the sub visible within
project, but not outside it.)

'Static' is a different kind of instruction. It affects the persistency of
variables within the sub -- that is, whether they hold their values between
calls. Declaring the sub as Static is effectively the same as declaring all
the variables within the sub as static.

However, none of these ways of declaring a sub makes the variables within
the sub visible to other code. They affect only whether the Sub itself is
public or private. The sub's variables are always private to the sub.
 

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