Applicaiton_Design

download Applicaiton_Design

of 14

Transcript of Applicaiton_Design

  • 8/8/2019 Applicaiton_Design

    1/14

    27/09/2010

    CPU255 - Introduction to ProgrammingLethbridge College 1

    Week 4

    Application DesignApplication Design

    Agenda Application Design

    5 Steps of Application Design

    Pseudocode

    TOE Chart Programming Conventions

    Comments

    Indentation

    Line Continuation

    Naming Conventions

    Tutorial 2

  • 8/8/2019 Applicaiton_Design

    2/14

    27/09/2010

    CPU255 - Introduction to ProgrammingLethbridge College 2

    5 Steps of Application Design 5 steps to complete an application effectively

    1. Plan the application

    Flow charts/Pseudocode, TOE charts,Sketch user-interfaces (find what works foryou)

    2. Build the Graphical User-Interface (GUI)

    3. Code the application

    4. Test and debug the application

    5. Assemble the documentation

    Help files, comments, technical report

    Pseudocode (pg. 90) List of steps written in plain English that

    describes what an object needs to do to performassociated tasks

    The pseudocode solution is translated byprogrammers into a language (VB) thatcomputers can understand

    Text Example Print Order Button (pg. 131)

    1. Hide the command buttons on the form

    2. Print the user form

    3. Re-display the buttons on the form

    4. Send the focus to the Clear Screen button

  • 8/8/2019 Applicaiton_Design

    3/14

    27/09/2010

    CPU255 - Introduction to ProgrammingLethbridge College 3

    TOE Chart (pg. 98) Tasks Objects Events

    3 Steps:1. Identify the TASKS the application needs to perform

    2. Identify the Objects required to complete the tasks

    3. Identify the Events required to trigger an object intoperforming its assigned task

    See pg. 98 for an example

    Programming Conventions Developers follow certain conventions when they write

    code

    Conventions dictate naming and documentation styles

    Helps other developers work with your code more easily

    Will even help you!

  • 8/8/2019 Applicaiton_Design

    4/14

    27/09/2010

    CPU255 - Introduction to ProgrammingLethbridge College 4

    Conventions continued Common conventions for Visual Basic:

    Comments

    Indentation

    Line Continuation

    Naming Conventions

    Comments Used to explain code (what it is doing)

    In VB the apostrophe () is used

    Anything after an is not interpreted by thecomputer

    In your applications always include 3 thingsat the top of the main forms code:

    1. Name:

    2. Date:

    3. Program Description:

  • 8/8/2019 Applicaiton_Design

    5/14

    27/09/2010

    CPU255 - Introduction to ProgrammingLethbridge College 5

    Comments Comments appear green by default

    Comment/Uncomment a block of selected codeusing tools on the Edit toolbar

    'Send a message to the userMsgBox "CPU255 - Introduction to Programming is fun!"

    Comment block Uncomment block

    Indentation Do This:

    Dont do this:

    Private Sub Command1_Click()

    Dim x As Integer

    For x = 1 To 3

    y = 1 + x

    Next x

    End Sub

    Private Sub Command1_Click()

    Dim x As Integer

    For x = 1 To 3

    y = 1 + x

    Next x

    End Sub

  • 8/8/2019 Applicaiton_Design

    6/14

    27/09/2010

    CPU255 - Introduction to ProgrammingLethbridge College 6

    Line Continuation

    VB allows you to break a long line of code over into thenext line

    Use a space followed by an underscore ( _) at the pointyou want the line to break

    This can be very useful to help improve your codereadability

    Example:

    Naming Conventions When adding a form or control VB assigns it a

    default name

    Example: the 1st Command Button added to a

    form is named Command1, and the 2nd isCommand2

    In this course, you must follow the namingconvention syntax for:

    1. Controls

    2. Forms

    3. Variables (discussed next lecture)

  • 8/8/2019 Applicaiton_Design

    7/14

    27/09/2010

    CPU255 - Introduction to ProgrammingLethbridge College 7

    Naming Conventions continued Controls & Forms syntax

    Prefix 3 lower case letters specify type Example: cmd Command Button

    Remaining letters describe the control Example: Exit

    Command1 cmdExit

    Naming Conventions continuedQ What if there is more than one word used in

    the naming convention?

    txtFirstname

    txtFirstName

    A Capitalize FirstLettersOfWords.

    Example:

    a text box used to enter customers first name:

  • 8/8/2019 Applicaiton_Design

    8/14

    27/09/2010

    CPU255 - Introduction to ProgrammingLethbridge College 8

    Control Prefix Naming Conventions

    Control Default Name Name Prefix

    Check Box Check1 chk

    Combo Box Combo1 cbo

    Command Button Command1 cmd

    Form Form1 frm

    Frame Frame1 fra

    Image Image1 img

    Label Label1 lblList Box List1 lst

    Option Button Option1 opt

    Picture Box Picture1 pic

    Text Box Text1 txt

    Timer Timer1 tmr

    More about Visual Basic

    Things you need to know to complete Tutorial #2

    Methods

    Functions TabIndex Property

    Access Keys

    Concatenation Operators

    Assigning Properties at run-time

  • 8/8/2019 Applicaiton_Design

    9/14

    27/09/2010

    CPU255 - Introduction to ProgrammingLethbridge College 9

    Methods

    Methods are pre-defined procedures built intoobjects

    They define the behaviour (or tasks) of objects

    Examples of Methods used in Tutorial 2:

    object.SetFocus

    [form.]PrintForm

    Built-In Functions Most programming languages come with a prewritten

    set of functions

    Functions are pre-defined procedures or routines

    Similar to object methods, however functions return avalue

    Two types of Functions:

    1. Numeric Functions

    2. String Functions

  • 8/8/2019 Applicaiton_Design

    10/14

    27/09/2010

    CPU255 - Introduction to ProgrammingLethbridge College 10

    Functions1. Numeric Functions:

    Deal with ways of manipulating and converting numbers

    2. String Functions: Deal with ways of manipulating and converting strings

    String Functions used in Tutorial 2:1. Val()

    2. Format()

    Val() Function (pg. 143)

    Used to translate a string into a number

    Usage: Val(string) Example:

    Val(10) Returns 10

    Val(Kyle) Returns 0

  • 8/8/2019 Applicaiton_Design

    11/14

    27/09/2010

    CPU255 - Introduction to ProgrammingLethbridge College 11

    Format() Function (pg. 144)

    Format(5459.4 , ##,##0.00) Returns 5,459.40

    Format(1000000, currency) Returns $1,000,000.00

    Used to format numbers, dates and times

    Usage: Format(expression, format) Example:

    TabIndex Property of Objects (object.TabIndex)

    Permits the user to access active controls on

    forms by pressing the Tab key Order of access is determined by predefined

    order as set by the programmer

    First object added to a form is assigned adefault TabIndexvalue of0

  • 8/8/2019 Applicaiton_Design

    12/14

    27/09/2010

    CPU255 - Introduction to ProgrammingLethbridge College 12

    Access Keys Allows users to select objects using the Alt key in

    combination with a number or letter (must be unique) To set an access key place the ampersand (&) in the

    caption property

    Example:

    &Save File E&xit

    Access Keys continued

    To set focus to a text box place the ampersand in thelabel controls caption property that precedes the textbox

    Label control Text box

    lblFirstName.Caption = &First Name:

  • 8/8/2019 Applicaiton_Design

    13/14

    27/09/2010

    CPU255 - Introduction to ProgrammingLethbridge College 13

    Concatenation Operators

    Join multiple strings into a single string

    The plus sign (+) and ampersand (&) can beused to concatenate strings

    Example:

    The & operator is recommended for stringconcatenation

    Assigning Properties at Run-time

    Assignment statements assign a value to a property(attribute) of an object

    Syntax: [form.]object.property = value

    Square brackets [] indicate optionalinformation

    Italicized words indicate requiredinformation

    The period between the object and the property iscalled the dot member selection property

    What appears to the right of the period is a member ofwhat appears to the left

  • 8/8/2019 Applicaiton_Design

    14/14

    27/09/2010

    CPU255 - Introduction to ProgrammingL thb id C ll 14

    Getting Help F1 key for context-sensitive help

    MSDN Library Visual Studio 6.0

    World Wide Web

    Hands-On Tutorial Tutorial 2

    Lesson B Building the User Interface

    Lesson C Coding, Testing, Debugging, andDocumenting the Application