Naming Conventions - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Naming Conventions

Description:

Opt Option/Radio Button Img Image. Wizard Code. Private Sub CmdOpenSplitting_Click ... Resume Exit_CmdOpenSplitting_Click. End Sub. Housekeeping ... – PowerPoint PPT presentation

Number of Views:133
Avg rating:3.0/5.0
Slides: 20
Provided by: colin82
Category:

less

Transcript and Presenter's Notes

Title: Naming Conventions


1
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

2
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

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

4
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

5
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)

6
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

7
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

8
The Do Statement
  • Syntax
  • Do While Until condition
  • statementsExit Do
  • statements
  • Loop
  • Or
  • Do
  • statementsExit Dostatements
  • Loop While Until condition
  • Example - Factorials e.g. 4! 4321
  • Dim input_value
  • Dim multiplier As Integer
  • Dim result As Long
  • txtInput.SetFocus
  • input_value txtInput.Text
  • multiplier input_value
  • result input_value
  • Do Until multiplier 1
  • result result (multiplier - 1)
  • multiplier multiplier - 1
  • Loop
  • TxtOutput.SetFocus
  • TxtOutput.Text input_value "! " result

9
The For Next Statement
  • Syntax
  • For counter start To end Step step
  • statementsExit Forstatements
  • Next counter
  • Example
  • Dim input_value
  • Dim multiplier As Integer
  • Dim result As Long
  • txtInput.SetFocus
  • input_value txtInput.Text
  • result input_value
  • For multiplier input_value To 2 Step -1
  • result result (multiplier - 1)
  • Next multiplier
  • TxtOutput.SetFocus
  • TxtOutput.Text input_value "! " result

10
Low-level Documentation
  • Code is not like English
  • Intimate knowledge of code doesnt last
  • Help others to understand your code

11
White Space
  • VBA ignores its use
  • Blank lines
  • groups blocks of code
  • Indentation
  • shows association
  • Line Continuation
  • If first_number gt 50 And second_number gt 50 And
    third_number gt 50 Then
  • If first_number gt 50 And second_number gt 50 _
  • And third_number gt 50 Then

12
In-line Comments
  • Anything after a single quote on one line is
    ignored by VBA
  • Comments
  • Debugging
  • The If statement tests if the three numbers are
    greater than 50 resulting in an appropriate
    message
  • If first_number gt 50 And second_number gt 50 And
    third_number gt 50 Then
  • Text1.SetFocus
  • Text1.Text "these are both big numbers"
  • Else
  • Text1.SetFocus
  • Text1.Text "at least one of these numbers
    is small"
  • End If

13
High-level Documentation
  • How do all the objects in your system fit
    together?
  • How do you know where form/report or module code
    is used?

14
System Hierarchy Chart
  • Create shapes that represent each object
  • Use them consistently
  • Connecting lines have arrows that show sequence
  • Split diagram across more than one page
  • Use drawing tool or by hand

15
Partial System Hierarchy Chart
16
Annotated Screenshots (1)
  • Draw by hand or captured from the system
  • Point to object with line and explain its
    function
  • Use a numeric key for screens with large numbers
    of objects

17
Annotated Screenshots (2)
Form demonstrating different data types
1 - Text1 Assigned maximum integer value 2 -
Text2 Assigned a Long 3 - Text3 Assigned a
decimal number 4 - Text4 Assigned a date 5 -
Text5 A text value assigned to a variant
Command0 When clicked will assign
appropriate values to the textboxes
18
Testing (1)
  • Black Box Testing
  • Tests outputs against inputs
  • White Box Testing
  • Tests all the paths in a program
  • Unit Testing
  • Validating input
  • Test system elements
  • Integration Testing
  • Putting it all together

19
Testing (2)
  • Test Data
  • Boundary testing
  • Type testing
  • Testing Regime
  • What you are testing
  • Data used
  • Anticipated result
  • Actual Result
Write a Comment
User Comments (0)
About PowerShow.com