Outline - PowerPoint PPT Presentation

1 / 29
About This Presentation
Title:

Outline

Description:

Introduction to Visual Basic (VBA) ENGR 112. Programming Languages ... VBA (Visual Basic for Applications) Visual C and C . Develop ... Basic Strings ... – PowerPoint PPT presentation

Number of Views:45
Avg rating:3.0/5.0
Slides: 30
Provided by: kenf6
Category:
Tags: basic | outline

less

Transcript and Presenter's Notes

Title: Outline


1
Outline
  • Software and Programming
  • Program Structure
  • Tools for Designing Software
  • Programming Languages
  • Introduction to Visual Basic (VBA)

2
ENGR 112
  • Programming Languages

3
Types 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")
4
Types of Programming
  • Event-Driven
  • Waits for an event to trigger program execution
  • Modular programming
  • No start/stop point in program

5
Types of Programming
  • Event-Driven

6
Event-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
7
Programming 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

8
Programming 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

9
Programming 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

10
VBA 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)
12
Advantages 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

13
Visual Basic Overview
  • Objects
  • Events
  • Numbers
  • Strings
  • Variables
  • Operators

14
Elements of a Visual Basic
  • Objects Events

15
Object 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)

16
Objects With Names
lblEngr112
picCOE
txtInputA, txtInputB
picResults
cmdAddButton
17
Visual 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

18
Elements 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 ()

19
Visual Basic Integers
  • Sequence of digits with no
  • Commas
  • Decimal points
  • Negative numbers preceded by -
  • Positive numbers optionally preceded by

20
Single Precision Real Numbers
  • Standard Representation
  • Integer (whole number) portion
  • Decimal point
  • Unsigned integer (fractional) portion

21
Visual 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

22
Visual 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

23
Variable Names
  • a, b, c, ..., x, y, z
  • distance, speed, time, average
  • rateOfIncrease, startingTime, hoursPerWeek
  • rate_of_increase, starting_time, hours_per_week

24
Declaring 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!!

25
VB Arithmetic Operators
  • Addition () a b
  • Subtraction (-) a - b
  • Multiplication () a b
  • Division (/) a / b
  • Exponentiation () a b

26
Arithmetic Order of Evaluation
  • 1. Exponentiation (R - L)
  • 2. Multiplication division (L-R)
  • 3. Addition subtraction (L-R)

27
Examples of Evaluation (1)
28
Converting Formulas to VB
(1.0 / (a b)) 2 / ((1.0 / c 1.0 / d)
(e / f - g / h))
29
String Operator
  • Concatenation ()

good bye goodbye
Write a Comment
User Comments (0)
About PowerShow.com