Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

27/09/2010

Week 4

Application Design

Agenda
 Application Design
 5 Steps of Application Design
 Pseudocode
 TOE Chart
 Programming Conventions
 Comments
 Indentation
 Line Continuation
 Naming Conventions
 Tutorial 2

CPU255 - Introduction to Programming


Lethbridge College 1
27/09/2010

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 for
you)
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 perform
associated tasks
 The pseudocode solution is translated by
programmers into a language (VB) that
computers 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

CPU255 - Introduction to Programming


Lethbridge College 2
27/09/2010

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 into
performing 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!

CPU255 - Introduction to Programming


Lethbridge College 3
27/09/2010

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 the
computer
 In your applications always include 3 things
at the top of the main forms code:
1. Name:
2. Date:
3. Program Description:

CPU255 - Introduction to Programming


Lethbridge College 4
27/09/2010

Comments
 Comments appear green by default
'Send a message to the user
MsgBox "CPU255 - Introduction to Programming is fun!"

 Comment/Uncomment a block of selected code


using tools on the Edit toolbar
Comment block Uncomment block

Indentation
 Do This:
Private Sub Command1_Click()
Dim x As Integer
For x = 1 To 3
y=1+x
Next x
End Sub

 Don’t do this:
Private Sub Command1_Click()
Dim x As Integer
For x = 1 To 3
y=1+x
Next x
End Sub

CPU255 - Introduction to Programming


Lethbridge College 5
27/09/2010

Line Continuation
 VB allows you to break a long line of code over into the
next line
 Use a space followed by an underscore ( _) at the point
you want the line to break
 This can be very useful to help improve your code
readability
 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 is
Command2
 In this course, you must follow the naming
convention syntax for:
1. Controls
2. Forms
3. Variables (discussed next lecture)

CPU255 - Introduction to Programming


Lethbridge College 6
27/09/2010

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 continued…


Q What if there is more than one word used in
the naming convention?
A Capitalize FirstLettersOfWords.

 Example:
 a text box used to enter customers first name:
txtFirstname
txtFirstName

CPU255 - Introduction to Programming


Lethbridge College 7
27/09/2010

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 lbl
List 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

CPU255 - Introduction to Programming


Lethbridge College 8
27/09/2010

Methods
 Methods are pre-defined procedures built into
objects
 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 a
value
 Two types of Functions:
1. Numeric Functions
2. String Functions

CPU255 - Introduction to Programming


Lethbridge College 9
27/09/2010

Functions
1. 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

CPU255 - Introduction to Programming


Lethbridge College 10
27/09/2010

Format() Function (pg. 144)


 Used to format numbers, dates and times
 Usage: Format(expression, format)
 Example:
Format(5459.4 , “##,##0.00” ) Returns ”5,459.40”
Format(1000000, “currency” ) Returns ”$1,000,000.00”

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 a
default TabIndex value of 0

CPU255 - Introduction to Programming


Lethbridge College 11
27/09/2010

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 the
label controls caption property that precedes the text
box

Label control Text box

lblFirstName.Caption = “&First Name:”

CPU255 - Introduction to Programming


Lethbridge College 12
27/09/2010

Concatenation Operators
 Join multiple strings into a single string
 The plus sign (+) and ampersand (&) can be
used to concatenate strings
 Example:

 The & operator is recommended for string


concatenation

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 optional information
 Italicized words indicate required information
 The period between the object and the property is
called the dot member selection property
 What appears to the right of the period is a member of
what appears to the left

CPU255 - Introduction to Programming


Lethbridge College 13
27/09/2010

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, and
Documenting the Application

CPU255 - Introduction to Programming


Lethbridge College 14

You might also like