Download presentation
Presentation is loading. Please wait.
Published byHugh Morrison Modified over 9 years ago
1
Programming Principles Spreadsheet-Based Decision Support Systems Chapter 24: Aslı Sencer MIS 463
2
2 Overview 24.1 Programming Practices 24.2 Clarity 24.3 Efficiency 24.4 Summary
3
3 Programming Practices Issues related to coding in VBA for spreadsheet-based DSS development. Clarity –Coding with a consistent style; –Using naming standards; –Having clear comments; Increasing coding efficiency.
4
4 Consistent Style Use a consistent style for formatting, organizing, and commenting your code. Spacing, indenting, line length should be consistent –Keep procedures and functions far enough so that scanning is easy –Indent to signify the beginning and end of a loop –Line length should be long enough to avoid scroll back and forth –Break lines at logical places Be consistent at error checking –Check inputs in all input forms and worksheets Indenting not clear: If A is True Then ‘actions 1 ElseIf B is True Then ‘actions 2 End If Clearer indenting style: If A is True Then ‘actions 1 ElseIf B is True Then ‘actions 2 End If
5
5 Naming Use naming standards for variables and procedures. –Abbreviate names so that they are not confused with other meanings. Ex:NumFac ? –When there is more than one word in a name capitalize the first letter. Ex: MinVal –Create descriptive names that are not lengthy Ex: “MinVal”, “SumProfit”, “MaxPrice” “FindMinCost”, “GetUserInfo” –Loop counters are usually i and j. May also use “iter”, or “run” Naming standards also apply to control names and specific data types, Ex: The name of a textbox should start with “txt”, The name of a form should start with with “frm”, boolean varaible may start with “IsDone” or “DoAnimation” for constants use PI, INFINITY Procedure names: Use CalcReturn instead of Calc Function names: FindMinCost, GetUserInfo
6
6 Documentation Make comments clear throughout the code. Describe procedure functionality and loop and logical flow.
7
7 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 ‘do actions Next i
8
8 Efficiency (cont) Static structure: Dim CostArray(10) as Double Dynamic structure: Dim CostArray() As Double, CostSize As Integer ReDim CostArray(CostSize) -------------------------------------- Static structure: ‘paste in output table Range(“A1”).PasteSpecial Dynamic structure: Dim OutputTable As Range Set OutputTable = Range(“A1”) OutputTable.PasteSpecial
9
9 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.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.