Empty Variables

K

Kerry

Hi

I have many many variables within my VBA project, some
may be used within a session, some not. I have to
declare many of the variables as public due to how their
values are being used.

The problem I have is that once the session is finished
and the form is closed I may want to start again,
obviously the variables do not empty. As many of my
variables are public I could restart word but this is not
very user friendly. I could add commands into my session
startup procedure which will empty all the variables but
there are around 50 of them plus arrays.

Do you have any advice on what I can do to resolve this
issue please? I have looked up emptying variables and
have only found information about the terminate event and
not sure whether this is what I need, I would be very
grateful for any advice.

Thank you very much.

Kerry.
 
J

JB

Kerry said:
Hi

I have many many variables within my VBA project, some
may be used within a session, some not. I have to
declare many of the variables as public due to how their
values are being used.

The problem I have is that once the session is finished
and the form is closed I may want to start again,
obviously the variables do not empty. As many of my
variables are public I could restart word but this is not
very user friendly. I could add commands into my session
startup procedure which will empty all the variables but
there are around 50 of them plus arrays.

Do you have any advice on what I can do to resolve this
issue please? I have looked up emptying variables and
have only found information about the terminate event and
not sure whether this is what I need, I would be very
grateful for any advice.

Thank you very much.

Kerry.
Hi Kerry,
Best way to write code is to use as few Public variables as possible and
pass any parameters you need to subs & functions. Other than that I'm
not sure what you could do except have a procedure like you already
suggested.

How are their values being used that forces you to use publics?

J
 
K

Kerry

OK - R U Ready - its quite a biggie!

My project is to assist users in creating very large
tender documents to help them bid for construction
business. Tenders comprise of many sections - Health &
Safety, Financial & Project Management to name a few
(there are 16 to choose from with the option of extra
sections which are unamed so the users can customise
them) Users will not only want to start sections from
scratch but require the option to insert a section they
have used on previous tenders.

There are 5 teams who could create a tender, the template
logos differ depending on the team and there is 6th
standard overall company template. Some sections include
file inserts such as Team CVs or Case studies.

The user is presented with a form where they enter client
details, team info. Users then choose which sections to
insert, also if necessary which inserts to include. The
section choices offer new sections, previously created
sections, standard template or team template options.

Once all section decisions have been made the user then
decides the order in which the sections appear in the
tender so as each section can be numbered.

Upon clicking finish each section is built in to a
seperate word document, inserting the cv's/case studies
as it goes. All documents are allocated a number which
then carries through the document for level 2 & 3
numbering. A front page is also created to be used as a
contents page at the fron tof the tender. There are many
many other things that this project will allow the users
to do including renumbering, inserting A£ pages,
landscape pages and so on.

As many many documents are being created, modified and
additional information inserted public variables are an
absolute must. I hope I haven't given you too much
information. Many thanks for your help. It looks like I
will have to empty each varible in the startup
procedure!! Do you know of a quick way to empty arrays, I
have 4 of them storing up to 30 ??

Many thanks.

Kerry.
 
J

JB

Kerry said:
OK - R U Ready - its quite a biggie!

My project is to assist users in creating very large
tender documents to help them bid for construction
business. Tenders comprise of many sections - Health &
Safety, Financial & Project Management to name a few
(there are 16 to choose from with the option of extra
sections which are unamed so the users can customise
them) Users will not only want to start sections from
scratch but require the option to insert a section they
have used on previous tenders.

There are 5 teams who could create a tender, the template
logos differ depending on the team and there is 6th
standard overall company template. Some sections include
file inserts such as Team CVs or Case studies.

The user is presented with a form where they enter client
details, team info. Users then choose which sections to
insert, also if necessary which inserts to include. The
section choices offer new sections, previously created
sections, standard template or team template options.

Once all section decisions have been made the user then
decides the order in which the sections appear in the
tender so as each section can be numbered.

Upon clicking finish each section is built in to a
seperate word document, inserting the cv's/case studies
as it goes. All documents are allocated a number which
then carries through the document for level 2 & 3
numbering. A front page is also created to be used as a
contents page at the fron tof the tender. There are many
many other things that this project will allow the users
to do including renumbering, inserting A£ pages,
landscape pages and so on.

As many many documents are being created, modified and
additional information inserted public variables are an
absolute must. I hope I haven't given you too much
information. Many thanks for your help. It looks like I
will have to empty each varible in the startup
procedure!! Do you know of a quick way to empty arrays, I
have 4 of them storing up to 30 ??

Many thanks.

Kerry.



as possible and


than that I'm


you already
Sounds quite complicated! Maybe too much so. Are you giving them too
many options and yourself too much work?

To erase arrays your better either using the "Erase strMyArray()"
statement or use dynamic arrays and just ReDim them which clears all
data. ReDim MyArray(iNum).

Rather than using public variables you could make use of the custom
document properties to store metadata on the documents and this should
give clues as to exactly what type of document it is your dealing with.

You can then have all the information you need in the document
properties and can get to this without opening the docuemnt.

HTH

J
 
P

Pete Bennett

Probably a more constructive way to do this (if metadate wasn't a good enough
method) would be to store the data in a class (or series of classes). That
way doing a Set clsData = Nothing would clear the whole kit and caboodle in
one fell blow.

Actually, when you first instantiate the class data, you'd have to
initialise it as a new object, so that would have the same effect.

Classes have a fiar bit of a learning curve to learn how to use them, but
once you've got it in your head, you can do some really powerful things with
them. They save an anwful lot of convuluted coding as well. With the amount
of data you've got, a few well constructed classes would make your code into
a thing of beauty.


Pete.
 

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