Introduction to Programming - PowerPoint PPT Presentation

1 / 28
About This Presentation
Title:

Introduction to Programming

Description:

Control how and when these commands are issued ... Text1.Text = 2000 - Year(InputBox('Please enter your date of birth', 'Date of Birth' ... – PowerPoint PPT presentation

Number of Views:41
Avg rating:3.0/5.0
Slides: 29
Provided by: colin82
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Programming


1
Introduction to Programming
  • Programming allows you to
  • Issue commands to make the system do something
  • Control how and when these commands are issued
  • In general, each line in a program consists of a
    single command or control

2
Lecture 7Colourful Programming
  • Intro to VBA programming
  • The programming environment
  • Setting form properties
  • Data types
  • Variables
  • Constants
  • Example/ Tutorial
  • HTML Hypertext Markup Language

3
Control Constructs
  • Sequence
  • Each line of code is performed in sequence
  • Selection
  • At test of truth determines if one block of code
    or another is performed
  • Iteration
  • The same block of code is repeated whilst or
    until something is true

4
Visual Basic for Applications
  • A version of Visual Basic
  • Most of the Microsoft Office applications have
    their own version of VBA
  • The ability to generalise from VBA to VB
  • Access VBA contains a large number of commands
    directly associated with the manipulation of
    Access databases

5
Event-Driven Languages
  • vs Procedural and Declarative
  • Associated with events that may or may not occur
  • Internally or externally determined
  • User determines the order events occur
  • This does not mean that procedural code is not
    written

6
Object-Based Programming
  • Everything, including the form itself, is an
    object
  • Code is generally associated with an object and
    some event performed on it
  • Each object can have one or more blocks of code
    associated with it depending on what you do with
    the object

7
Design-Time
  • Each of those objects has a set of properties
    associated with it that you can change
  • Every time you create an object, it is
    independent of any other object
  • Changes at design-time determines the state of
    those objects at run-time

8
Object Properties
9
Run-Time
  • Each type of object has a pre-defined set of
    actions that the user can do to it
  • Code may be written against any of them
  • Each block of code associated with an event is
    called a Procedure
  • The procedure will not be run unless that event
    occurs

10
Code Window (1)
11
Code Window (2)
12
Background
13
Environment (1)
14
Environment (2)
  • Private Sub Command0_Click()
  • Form.RecordSelectors False
  • Form.DividingLines False
  • Form.NavigationButtons False
  • Form.ScrollBars 0
  • Form.Caption "Looking Good!"
  • Command0.Left 5 567
  • Command0.Top 1 567
  • Command4.Left 5 567
  • Command4.Top 3 567
  • Command0.Caption ""
  • Command4.SetFocus
  • Command0.Enabled False
  • Command4.Caption "Return"
  • End Sub

15
Environment (3)
  • Private Sub Command4_Click()
  • Form.RecordSelectors True
  • Form.DividingLines True
  • Form.NavigationButtons True
  • Form.ScrollBars 3
  • Form.Caption ""
  • Command0.Left 1 567
  • Command0.Top 2 567
  • Command4.Left 9 567
  • Command4.Top 2 567
  • Command0.Enabled True
  • Command0.Caption "Command0"
  • Command4.Caption "Command4"
  • End Sub

16
Algorithm Design
  • Probably the hardest part of programming
  • What do you want the program to do?
  • What objects do you need?
  • Which event on what object?
  • The steps within each procedure
  • How objects interact with one another

17
De-Bugging (1)
  • There will always be errors!
  • The most frustrating part of programming and
    takes the most time
  • VBA is an Interpreted language
  • Run it as soon as you write it
  • Checked for Syntax as it runs
  • Syntax rigidly applied
  • Runs but doesnt do what you want
  • Stops running

18
De-Bugging (2)
19
Text Entry (1)
20
Text Entry (2)
  • Private Sub Form_Load()
  • Text1.Visible False
  • Label6.Visible False
  • Label7.Visible False
  • End Sub

21
Text Entry (3)
  • Private Sub Command0_Click()
  • Label6.Visible True
  • Label7.Visible True
  • Text1.Visible True
  • Text1.SetFocus
  • Text1.Text ""
  • Text1.Text 2000 - Year(InputBox("Please enter
    your date of birth", "Date of Birth"))
  • Command0.SetFocus
  • End Sub

22
Data Types
  • String Text, including input from a TextBox,
    values displayed in a Label or values stored in
    the program between quotes
  • Integer Whole numbers, for very large numbers you
    may need a Long
  • Single Numbers containing decimal points, for
    large decimal numbers you may need a Double.
  • Date Often useful if you are wanting to compare
    one date against another
  • Variant As its name implies a Variant can vary
    and will take on the characteristics of whatever
    is passed to it. For example if an Integer value
    is passed to a variant it will act as though it
    is an Integer from that point

23
Variables (1)
  • In programming you often want to do something
    that requires the system to remember things
  • Variables are areas set aside in the computers
    memory, for the duration of the program run
  • You can assign values to variables
  • As their name implies, the values they store are
    allowed to vary

24
Variables (2)
  • Each variable must have a unique name so that
    when the name is mentioned the system will know
    where to look
  • The variable must be of a particular type
  • To set aside an area of memory of a given type
    with a particular name, you need to declare it
    first

25
Variables (3)
  • Variables
  • Syntax Dim name As data type
  • e.g. Dim exam_result As Integer
  • Constants
  • Syntax Const name is assigned Value
  • Const VAT 1.175

26
Example
27
Example
  • Private Sub Command0_Click()
  • Dim whole_number As Integer
  • Dim big_whole_number As Long
  • Dim decimal_number As Single
  • Dim date_value As Date
  • Dim can_be_anything As Variant
  • whole_number 32767
  • Text1.SetFocus
  • Text1.Text whole_number
  • big_whole_number 33333
  • Text2.SetFocus
  • Text2.Text big_whole_number
  • decimal_number 32767 / 2
  • Text3.SetFocus
  • Text3.Text decimal_number
  • date_value Date
  • Text4.SetFocus
  • Text4.Text date_value
  • can_be_anything "This is text"
  • Text5.SetFocus
  • Text5.Text can_be_anything
  • Command0.SetFocus
  • End Sub

28
Tutorial
Write a Comment
User Comments (0)
About PowerShow.com