COMM 1A Application Building - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

COMM 1A Application Building

Description:

Resume Exit_CmdOpenSplitting_Click. End Sub. University of Sunderland ... Wizard code works in exactly the same way as code you create and can be modified ... – PowerPoint PPT presentation

Number of Views:15
Avg rating:3.0/5.0
Slides: 11
Provided by: colin82
Category:

less

Transcript and Presenter's Notes

Title: COMM 1A Application Building


1
  • COMM 1A Application Building
  • Unit 8

2
Introduction
  • Objectives for the Session
  • To be aware of the need for re-naming objects and
    a common Naming Convention
  • To be able to understand the nature of Wizard
    Code
  • To understand the need for Housekeeping
  • To understand the syntax and use of the If
    construct
  • To understand the syntax and use of the Select
    Case construct

3
Naming Conventions
  • Objects and variables must have a unique name
  • Default names
  • Rename, as a minimum, all objects that are
    influenced by code
  • Do it before you write code!
  • Cmd Command Buttons Chk CheckBox
  • Lbl Label Cbo ComboBox
  • Txt TextBox Lst ListBox
  • Opt Option/Radio Button Img Image

4
Wizard Code
  • Private Sub CmdOpenSplitting_Click()
  • On Error GoTo Err_CmdOpenSplitting_Click
  • Dim stDocName As String
  • Dim stLinkCriteria As String
  • stDocName "Splitting lines of code"
  • DoCmd.OpenForm stDocName, , , stLinkCriteria
  • Exit_CmdOpenSplitting_Click
  • Exit Sub
  • Err_CmdOpenSplitting_Click
  • MsgBox Err.Description
  • Resume Exit_CmdOpenSplitting_Click
  • End Sub

5
Housekeeping
  • Delete an object with code and the code remains
  • Re-create the object and you get duplicate code
  • Tidy up as you go

6
Control Constructs
  • Control the flow of a program
  • Sequence
  • Each line of code is performed in order
  • Selection
  • One block of code is performed rather than
    another
  • Iteration
  • A block of code is repeated a number of times

7
The If Statement
  • Syntax
  • If condition Then statements Else else
    statements
  • Example
  • txtInput.SetFocus
  • If txtInput.Text Fred Then txtInput.BackColor
    RGB(100, 150, 175)

8
The If Statement
  • Syntax
  • If condition Then
  • statements
  • ElseIf condition-n Then
  • elseif statements
  • Else
  • else statements
  • End If
  • Example
  • txtInput1.Text.SetFocus
  • If txtInput1.Text Fred Then
  • txtOutput.SetFocus
  • txtOutput.Text Hello Fred
  • ElseIf txtInput1.Text Peter Then
  • txtOutput.SetFocus
  • txtOutput.Text Hello Peter
  • Else
  • txtOutput.SetFocus
  • txtOutput.Text Hello whoever you are
  • End If

9
The Select Case Statement
  • Syntax
  • Select Case testexpressionCase expressionlist-n
    statements-n ...Case Else else statements
  • End Select
  • Example
  • txtThree.SetFocus
  • Select Case txtThree.Text
  • Case "1"
  • txtOutput.SetFocus
  • txtOutput.Text "You typed 1"
  • Case "2"
  • txtOutput.SetFocus
  • txtOutput.Text "You typed 2"
  • Case Else
  • txtOutput.SetFocus
  • txtOutput.text What you have typed in not 1
    or 2
  • End Select

10
Summary
  • Get into the habit of re-naming objects
  • Wizard code works in exactly the same way as code
    you create and can be modified in the same way,
    if necessary
  • Housekeeping makes it easier for you and others
    to understand your system design
  • Selection is a logical test of truth and,
    regardless of the choice of construct, code will
    only be run if the test is true
Write a Comment
User Comments (0)
About PowerShow.com