1 / 29

Outline

Outline. Software and Programming Program Structure Tools for Designing Software Programming Languages Introduction to Visual Basic (VBA). ENGR 112. Programming Languages. Types of Programming. Procedural Strict sequence of processing steps Distinct start/stop points in program.

Download Presentation

Outline

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 <stdio.h> main() { printf("Content-type: text/html\n\n"); printf("<html>"); printf("Hello World!"); printf("</html>"); }

  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.SetFocus • 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 • Beginner’s 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. 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

  12. Visual Basic Overview • Objects • Events • Numbers • Strings • Variables • Operators

  13. Objects & Events Label Picture box (image) Text box Picture box (text) Command button Elements of a Visual Basic

  14. The most important properties (at least for the purpose of this course) are: Name (object’s name – important!!) Caption (text to be displayed by the object) Font (what the text looks like) Visible (how it links to other applications) Object Properties

  15. Objects With Names lblEngr112 picCOE txtInputA, txtInputB picResults cmdAddButton

  16. 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

  17. 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 (&) Elements of Visual Basic

  18. Visual Basic Integers • Sequence of digits with no • Commas • Decimal points • Negative numbers preceded by ‘-’ • Positive numbers optionally preceded by ‘+’

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

  20. 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 = “

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

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

  23. 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!!

  24. VB Arithmetic Operators • Addition (+) a + b • Subtraction (-) a - b • Multiplication (*) a * b • Division (/) a / b • Exponentiation (^) a ^ b

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

  26. 4 + 3 + 7 * 2 + 3 * 3 + 1 14 9 7 21 30 31 Examples of Evaluation (1)

  27. 2 1 a + b 1 c 1 d e f g h + - Converting Formulas to VB (1.0 / (a + b)) ^ 2 / ((1.0 / c + 1.0 / d) * (e / f - g / h))

  28. Concatenation (&) String Operator “good” & “bye” “goodbye”

More Related