Title: MIS 300 Management Information Systems
1MIS 300 Management Information Systems
- Computer Programming
- (continued from Software Overview)
2Creating SoftwareComputer Programming
- Tell the computer exactly what you want it to do
and how to do it - A very detailed business process model
- Flow chart the logic of the business process to
be programmed - The computer does what you tell it to do!
3From Source Code to Executable Program
Source code
Executable Program
Source code
Source code
Linker
Compiler
Libraries
Object Code
4Bugs
- What are bugs? Why bugs?
- Why does software have bugs?
- Syntax bug versus a logic bug?
- How can bugs be reduced?
- Testing, testing, testing
- Debugging utilities
- 125M Mars Orbiter lost metric conversion
problem - Was Y2K a bug?
5Object code, user doc
- What is difference between object code and source
code? - Example width03out.c, width03out.obj
- What is a compiler?
- Why is source code nice to have?
- Can you always get source code?
- Do you always get user documentation when you buy
software or an information system?
6They Write the Right StuffWriting Bug Free Code
- Software for space shuttle Lockheed Martin,
Inc. - CMM5 for on-board shuttle group
- How does their process support their mission?
- What is the culture like? What are the people
like? - How does their organizational structure support
their mission? - Comparison to typical software development?
7Access Macros
- Simple, powerful automation
- Respond to events with actions
- events usually user initiated such as?
- execute a sequence of tasks
- Can create relatively complex applications using
Macros with little or no VBA code - Some things can only be done with VBA
- Lets explore FineFood.mdb and Tutorial 9
8Recording Macros in Excel
- Useful for learning VBA
- Really useful for learning details of object
model - A way to start a program
- To use
- start recorder (Tools-Macro-Record New Macro)
- do stuff
- stop recorder (Push the stop button)
- go look/edit code in VBE
- Cant record logic
- Lets look at some examples in Recording.xls
9Where does code live in Access and Excel (and
Word, etc)?
- Code behind forms
- Code related to controls on forms
- Respond to events (e.g. button click)
- Code Modules
- General subroutines and functions
- Not specific to a form
- Visual Basic Editor for both
10Structured Programming Concepts
- Divide code into independent procedures
- Each with its own purpose
- Procedures related hierarchically
- They talk through a list of arguments or
parameters - Logic
- sequence
- selection
- iteration
11Main Program and SubroutinesDivide programs into
independent proceduresTalk via passed
parameters
Filename
Main Program
Results
Values
Results
Values
Read data file
Output results
2
3
1
Do calculations
12(No Transcript)
13Variables
- Temporary storage of values (recall from
algebra?) - Can do things like
- xx1
- AvgCost TotalCost/NumItems
- Declare variables with Dim
- pick data type for the variable
- Example Dim NumItems As Integer
Variable type
Variable name
14Some Data Types
- String for text like Bob Smith
- Integer integers in 32768 to 32768
- Long for bigger integers
- Boolean only True (-1) or False (0)
- Double numbers with decimals
- Currency monetary values
- Date for dates and times
- Object specific versions for each object type
- Variant let VBA decide how to deal with
15Control Logic Condition or Selection If Then
Else End If
Example syntax from Visual Basic
If some condition Then a bunch of statements
to be done if the condition is True Else a
bunch of statements to be done if the condition
is False End If
16Control Logic Looping or Iteration ForNext,
Do WhileLoop
For counter start To stop bunch of
statements to be repeated Next counter
Example syntax from Visual Basic
Do While some condition bunch of statements
to be repeated Loop
17The Averaging Program
- Ive written an Excel VBA program to
- Let user enter a series of numbers, one at a time
into a simple data input form - When the user is done entering numbers, calculate
the average of the numbers entered - Display the calculated average to the user
- Lets find use of
- Variables
- Sequence
- Selection
- Iteration
18Major OO Programming Concept 1Classes and
Objects
Object Oriented
19Microsoft Access Object Model TableDefs A
collection of tables
20The Object Model a car analogy
We have object called Car
Each Car is part of the collection Cars
Each Car has properties that describe it such as
make, model, color, price, age, purpose, etc.
Each Car has methods that control it such as
accelerate, stop, turn left, turn right,, etc.
21Object Model for Cars
- Hierarchical
- Collections are plural
- Each object has its own specific set of
properties and methods
Cars (Car)
Wheels (Wheel)
Horn
Hood
HoodOrnament
22Working with Objects in VBA
- Properties and Methods
- Appearance and behavior control
- SomeObject.SomeProperty
- SomeObject.SomeMethod method arguments
- Collections of Objects
- the Collection itself is an object
(adjective)
(noun)
(verb)
(adverbs)
23Accessing specific objects in collections and
down hierarchy
- By index number
- By name
- Down hierarchy
- Worksheets(BreakEvenModel).Range(FCost).Value
Lets look at BreakEven.xls
Worksheets(1)
Worksheets(BreakEvenModel)
Dots separate objects in hierarchy
24Major OO Programming Concept 2Inheritance and
Methods
25Major OO Programming Concept 3Messages and
Polymorphism (?!)
26Object Property Values
- Car Object is a template for creating specific
car instances (inheritance) - Each car can have its own set of values for each
property
NOT a real program!
Set property values
Use Drive method (send message)
Check a property value and use a method if value
meets condition
27Simple Communication with User
- MsgBox show user message, get button click
response - InputBox get a single value from the user
28Some programming style tips
- Use meaningful variable names
- Indent
- Use lots of comments
- Create End If, Loop, End With, Next right after
you create If, Do While, With, For so you dont
forget - Use white space
29Programming with VBA
- Figure out what you logically want to accomplish
- Flow chart and/or pseudo-code
- Figure out which objects you need to
create/modify/access. - Figure out how to use those objects properties
and methods to do what you want to do. - Hunting through help, common sense, object
browser, record a macro
30Visual Basic Editor
- Project Explorer
- Code Modules
- Immediate Window
- Object Browser
- Locals
- Watch
- Run, continue, reset
- Single step into, over out
- Breaking out
- Using Breakpoints
- Auto List Members
- Auto Quick Info
31The Averaging ProgramRevisited
- Ive written an Excel VBA program to
- Let user enter a series of numbers, one at a time
into a simple data input form - When the user is done entering numbers, calculate
the average of the numbers entered - Display the calculated average to the user
- Well explore in Access (Program2000.mdb)
- More about the Visual Basic Editor
- Lets figure out how the code works
- Make some program enhancements