Title: Outline
1Outline
- Software and Programming
- Program Structure
- Tools for Designing Software
- Programming Languages
- Introduction to Visual Basic (VBA)
2ENGR 112
3Types of Programming
- Procedural
- Strict sequence of processing steps
- Distinct start/stop points in program
include ltstdio.hgt main()
printf("Content-type text/html\n\n")
printf("lthtmlgt") printf("Hello
World!") printf("lt/htmlgt")
4Types of Programming
- Event-Driven
- Waits for an event to trigger program execution
- Modular programming
- No start/stop point in program
5Types of Programming
6Event-Driven
Procedure 1
Private Sub cmbDates_Click() Me.txtSSNScanned.SetF
ocus Call scanSSN End Sub Private Sub
cmdEndProgram_Click() If endProgram Then
End Else endProgram False End If End
Sub Private Sub txtSSNScanned_GotFocus() If
Me.cmbDates.Text "" Then MsgBox ("You need
to enter a date!") Me.cmbDates.SetFocus
Exit Sub End If End Sub
Procedure 2
Procedure 3
7Programming Languages
- Assembly Language
- Fast and most efficient
- Very difficult to program in
- Basic
- Beginners All-purpose Symbolic Instruction Code
- Easy to use
- Lacks total control
8Programming Languages
- Fortran
- FORmula TRANslator
- Great for mathematical programming
- Not good for other uses, e.g. graphics
- C and C
- Powerful tools
- Harder to use/learn than BASIC
- Can do anything
9Programming Languages
- Visual Basic
- Develop windows programs easily
- Powerful tool
- Not as much control as Visual C
- VBA (Visual Basic for Applications)
- Visual C and C
- Develop windows applications
- Not easy to learn
10VBA Macro Programming
- VBA is a general purpose programming language
that comes standard with Excel or Office. - Using VBA with Excel, powerful engineering
analysis tools can be developed quickly and with
minimum cost. - VBA can be used for many engineering tasks
- communicating with engineering databases
- analyzing engineering data
- automating worksheet construction
- engineering modeling and simulation
- creating charts and engineering wizards (i.e.
dialog boxes) - creating GUI's
11(No Transcript)
12Advantages of VBA
- Programmer does not need to be an expert Windows
programmer - Programmer creates GUI and defines what happens
when user interacts with it - Events are generated
- Push a button, move mouse, etc.
- This is called event-driven programming
13Visual Basic Overview
- Objects
- Events
- Numbers
- Strings
- Variables
- Operators
14Elements of a Visual Basic
15Object Properties
- The most important properties (at least for the
purpose of this course) are - Name (objects name important!!)
- Caption (text to be displayed by the object)
- Font (what the text looks like)
- Visible (how it links to other applications)
16Objects With Names
lblEngr112
picCOE
txtInputA, txtInputB
picResults
cmdAddButton
17Visual Basic Events
- Change initiated by user
- Load a Form
- Click on a button
- Mouse down/up, Mouse drag
- Key down, key press, etc.
- Causes an event procedure (subprogram) to execute
18Elements of Visual Basic
- Data
- Constants (data that does not change)
- Numbers (e.g., 1234.56)
- Strings (e.g., this is a string)
- Variables (names of data holders)
- Numbers
- Strings
- Operators
- Arithmetic (, -, , /, etc.)
- String ()
19Visual Basic Integers
- Sequence of digits with no
- Commas
- Decimal points
- Negative numbers preceded by -
- Positive numbers optionally preceded by
20Single Precision Real Numbers
- Standard Representation
- Integer (whole number) portion
- Decimal point
- Unsigned integer (fractional) portion
21Visual Basic Strings
- String
- Sequence of characters (a, b, c, ..., 0, 1, 2,
..., , !, ...) treated as a unit - Enclosed in double quotes in VB statement
- this is a string
- John Smith
- 737-2357
- a b
22Visual Basic Variables
- Variable
- Symbolic name for data value
- Name of data holder
- Name of a location in random access memory
- Variable names rules
- Must begin with a letter
- May contain only letters, digits, and underscores
(_) - Up to 255 characters long
23Variable Names
- a, b, c, ..., x, y, z
- distance, speed, time, average
- rateOfIncrease, startingTime, hoursPerWeek
- rate_of_increase, starting_time, hours_per_week
24Declaring Variable Types
- Two options
- Implicit declaration
- Explicit declaration
- Explicit declaration
- Dim name As String
- Dim count As Integer
- Dim average As Single
- Dim nextItem As Variant
- Explicit declaration is always preferable!!
25VB Arithmetic Operators
- Addition () a b
- Subtraction (-) a - b
- Multiplication () a b
- Division (/) a / b
- Exponentiation () a b
26Arithmetic Order of Evaluation
- 1. Exponentiation (R - L)
- 2. Multiplication division (L-R)
- 3. Addition subtraction (L-R)
27Examples of Evaluation (1)
28Converting Formulas to VB
(1.0 / (a b)) 2 / ((1.0 / c 1.0 / d)
(e / f - g / h))
29String Operator
good bye goodbye