Spreadsheet-Based Decision Support Systems Chapter 24: Programming Principles Prof. Name name@email.com Position (123) 456-7890 University Name
Overview 24.1 Programming Practices 24.2 Clarity 24.3 Efficiency 24.4 Summary
Programming Practices We summarize here what we feel are some important issues when coding in VBA for spreadsheet-based DSS development. We categorize these issues as follows: coding with a consistent style; using naming standards; having clear comments; and increasing coding efficiency.
Clarity Consistent Style Naming Documentation
Consistent Style Use a consistent style for formatting, organizing, and commenting your code. Indenting not clear: If A is True Then ‘actions 1 ElseIf B is True Then ‘actions 2 End If Clearer indenting style:
Naming Use naming standards for variables and procedures. “MinVal”, “SumProfit”, “MaxPrice” “FindMinCost”, “GetUserInfo” Naming standards also apply to control names and specific data types, such as Boolean. “IsDone”, “DoAnimation”
Documentation Make comments clear throughout the code. Describe procedure functionality and loop and logical flow.
Efficiency Always look for ways to improve your coding efficiency. Avoid redundancies and unnecessary code. Static structure: For i = 1 to 10 ‘do actions Next i Dynamic structure: For i = 1 to NumProducts
Efficiency (cont) Static structure: Dim CostArray(10) as Double Dynamic structure: Dim CostArray() As Double, CostSize As Integer ReDim CostArray(CostSize) -------------------------------------- ‘paste in output table Range(“A1”).PasteSpecial Dim OutputTable As Range Set OutputTable = Range(“A1”) OutputTable.PasteSpecial
Summary The most important programming principles are writing with a consistent style, using naming standards, including clear comments, and improving code efficiency. It is important to have a clear, readable, and understandable code. Documentation is an important part of any programming project. We accomplish documentation by placing comments throughout our code. We should continuously be working to improve our code by reducing the complexity of the logic and the time required.
Additional Links (place links here) Projectile Simple forms with basic Excel manipulation Birthday Simulation Simple simulation with statistical analysis Portfolio Management and Optimization Using the Solver