raven_squire
Board Regular
- Joined
- Jan 13, 2013
- Messages
- 99
Hello,
I am basically self taught with VBA and I am making more and more complex macros. I am finding that my variables are all over the place and I was wondering what the professionals do in regards to variables.
Do you declare all variables or just the significant ones?
With the insignificant variables (ones that are just used temperarily as part of a process) do you give them meaningful names? or just use random letters of the alphabet? X or Employee_Num_Int, Employee_Num_Int_Temp
Do you reuse insignificant variables e.g. I have used many "for x = 0 to FOO" type statements, do you reuse the same variable in the next statement or create a different variable for each one?
Do you declare all the variables at the top of the module or do you declare them at the start of the block of code that first uses it?
I feel like my inconsistency is making my code hard to follow making it harder to debug and expand on. The module that I am working on now has 20 variables declared at the start of the module. I have no idea how many insignificant variables I have used and reused. Then there is the other modules that I have written that used public variables to move data from one module to the next.
Any help or links to coding guidelines would be apreciated.
Thanks Steve
I am basically self taught with VBA and I am making more and more complex macros. I am finding that my variables are all over the place and I was wondering what the professionals do in regards to variables.
Do you declare all variables or just the significant ones?
With the insignificant variables (ones that are just used temperarily as part of a process) do you give them meaningful names? or just use random letters of the alphabet? X or Employee_Num_Int, Employee_Num_Int_Temp
Do you reuse insignificant variables e.g. I have used many "for x = 0 to FOO" type statements, do you reuse the same variable in the next statement or create a different variable for each one?
Do you declare all the variables at the top of the module or do you declare them at the start of the block of code that first uses it?
I feel like my inconsistency is making my code hard to follow making it harder to debug and expand on. The module that I am working on now has 20 variables declared at the start of the module. I have no idea how many insignificant variables I have used and reused. Then there is the other modules that I have written that used public variables to move data from one module to the next.
Any help or links to coding guidelines would be apreciated.
Thanks Steve
Last edited: