procedural programming - What scope should my data objects have in VBA -


i populating set of arrays worksheet data. manipulate data before writing out worksheet (see example below).

if want use same worksheet data again, how can avoid rewriting code populates arrays worksheet?

  • should write code in 1 long procedure don't need repopulate arrays?
  • should make arrays global can reused in several procedures?
  • should pass arrays procedures need them in long argument list?
  • any other options?
 sub manipulatedata()     dim people(1 max_data_row) string     dim projects(1 max_data_row) string     dim startdates(1 max_data_row) date     dim enddates(1 max_data_row) date     ...     loop through worksheet cells populate arrays     ...     array data  end sub 

i'd create class contain arrays private variables , create 1 public sub called initialise or similar loads , other subs/functions needed give functionality need.

that way don't have pass arrays around they're still not global. problem making them global it's more risk other code somewhere else change arrays in way code isn't expecting can hard find since might anywhere in codebase.

here's introduction classes in excel vba.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -