Need some general Tips and Tricks for programming !
If you must use persistent variables, maybe you can create a routine that
initializes them.
Public VariablesAreInitialized as boolean
====
Then you can use
if variablesareinitialized then
'keep going
else
call thatroutinethatinitializesthevariables
'include
'VariablesAreInitialized = true
'in that routine
end if
And make sure you force yourself to declare your variables.
Saved from an earlier post about why "option explicit" should be used.
I do it for a much more selfish reason.
If I add "Option Explicit" to the top of a module (or have the VBE do it for me
via tools|options|Editor tab|check require variable declaration), I know that
most of my typos will stop my code from compiling.
Then I don't have to spend minutes/hours looking at code like this:
ctr1 = ctrl + 1
(One is ctr-one and one is ctr-ell)
trying to find why my counter isn't incrementing.
And if I declare my variables nicely:
Dim wks as worksheet
not
dim wks as object
and not
dim wks as variant
I get to use the VBE's intellisense.
If I use "dim wks as worksheet", then I can type:
wks.
(including the dot)
and the VBE will pop up a list of all the properties and methods that I can
use. It saves time coding (for me anyway).
And one final selfish reason.
If I use a variable like:
Dim ThisIsACounterOfValidResponses as Long
I can type
Thisis
and hit ctrl-space and the VBE will either complete the variable name or give me
a list of things that start with those characters.
And by using a combination of upper and lower case letters in my variables, the
VBE will match the case found in the declaration statement.
ps. From what I've read, if you declare a variable as Integer, the modern pc
will have to spend time converting it to long. So I've stopped using "dim x as
integer". It's safer for me and quicker for the pc.
Bill Case wrote:
Hi;
While I am programming (experimenting) with VBA I have lots of crashes as I
try different things out. When a program crashes it loses all its public
setup variables and other entered data. Is there some general programing
tips to keep in mind so that I can setup my playing around so that I can
recover from a crash without having to close down the program and start up
again?
Just some general good practices tips.
I am using the MZ-tools add-on with VBE; but does anybody know of a good
Auto-complete tool I can add-on that helps complete non-VBA key words. VBE
has lots of that assistance, but I want something that helps complete my own
varibale, function and procedures names?
Regards Bill
--
Dave Peterson
|