You are on page 1of 12

Visual Basic -1 Quiz #1 Review

OOP Terminology

OOP Terminology
(continued)
Object-oriented program: one that focuses on
objects the program can use to accomplish its goal

OOP: Object-oriented programming


Class: blueprint used to create an object
Object:

Integrates processes and data into objects

Represents a real-world entity


Attributes (or properties): describe the object
Methods: behaviors or operations the object can
perform

Microsoft Visual Basic 2010: Reloaded, Fourth Edition

Procedure-oriented program: one that focuses on


individual tasks and their sequence

Visual Studio 2010

Application: program or suite of programs


Windows-based application:

Contains all the tools and features needed to create,


run, and test programs
Includes an editor and compiler

Has a Windows user interface


Runs on a desktop computer

Web-based application:

Visual Studio 2010:

IDE used to create Windows or Web-based programs


Includes Visual Basic 2010, Visual C++ 2010, &Visual
C# 2010, etc

Microsoft Visual Basic 2010: Reloaded, Fourth Edition

Visual Studio 2010 (continued)

Integrated Development Environment (IDE):

Microsoft Visual Basic 2010: Reloaded, Fourth Edition

Has a Web user interface


Runs on a server
Use a computer browser to access it

User interface: what the user sees and interacts with


when using an application
Microsoft Visual Basic 2010: Reloaded, Fourth Edition

The Me.Close Method

The Properties Window


Properties window: displays properties of selected
object
Default property values are assigned when an object
is created
Properties list:

Me.Close method: closes the current form


Method: predefined VB procedure that can be
invoked (called)

Left column displays names of properties


Settings box: Right column containing the current value
of each property

Microsoft Visual Basic 2010: Reloaded, Fourth Edition

Microsoft Visual Basic 2010: Reloaded, Fourth Edition

Planning an Application

IDE Windows
Toolbox: contains tools for creating the GUI
(Controls)

Plan the application before creating the user interface


Work jointly with the user
Define the tasks that need to be performed
Get copies of any currently used manual forms

Form control: acts as a container for other controls


Label control: contains text that a user cannot edit
Button control: performs an immediate action when
clicked
Container controls: - Binds other controls visually
and programmatically

Group Box Has Text Caption


Panel No Text Caption
Table Layout Panel Holds other controls in a table
format of Rows and Columns
Microsoft Visual Basic 2010: Reloaded, Fourth Edition

Identify the Tasks your application must perform


Identify Objects which you will assign to the tasks
Identify the triggering Events
Make a TOE (Task, Object, Event) chart:
Shows applications tasks, objects, and events

Design the user interface


7

Microsoft Visual Basic 2010: Reloaded, Fourth Edition

Identifying the Applications Tasks


(continued)

Identifying the Objects

First, review current user procedures and forms


Steps:

Assign each task to an object in the TOE


TextBox tool: instantiates a text box control
TextBox:

Identify the desired outputs and necessary inputs


Identify the processing needed to change the inputs
into the outputs
Identify the need to clear the screen between
transactions
Identify how the user will end the application

Microsoft Visual Basic 2010: Reloaded, Fourth Edition

Used to allow the user to input information

Use Labels to guide the user


Use Buttons to initiate the calculations
Generate Events

Microsoft Visual Basic 2010: Reloaded, Fourth Edition

10

TOE Chart

Identifying the Events


Text boxes: no special events needed for user to
enter the text (None that you have to code)
Labels: no special events needed to display the
prompts (None that you have to code)
Buttons:
Action must occur when each button is clicked
(Click Event) (You have to code these)

Microsoft Visual Basic 2010: Reloaded, Fourth Edition

11

Microsoft Visual Basic 2010: Reloaded, Fourth Edition

12

Designing the User Interface


(continued)

Designing the User Interface

Primary Windows (MainForm)

Follow Windows standards for:

Can be resized, minimized, maximized, and closed


by the user
Title Bar includes:

Consistency
Ease of use
Familiar look and feel

Minimize, Maximize, and Close buttons on the right


Control menu on the left

Primary window:
The main window in an application

Dialog boxes: windows used to support and


supplement a users activities in the primary window

Dialog Boxes
Can be closed only
Title Bar includes:
Close button and optionally a Help button
No control menu

Microsoft Visual Basic 2010: Reloaded, Fourth Edition

13

Arranging the Controls

14

Arranging the Controls (continued)

Guidelines:
Information should flow either vertically or
horizontally
Group related controls together using white space or
container controls

Container controls:
GroupBox control
Panel control
TableLayoutPanel control

Microsoft Visual Basic 2010: Reloaded, Fourth Edition

Microsoft Visual Basic 2010: Reloaded, Fourth Edition

15

Control Guidelines:
Use a label with each text box
Left-align the labels text (I prefer Right-align)
Position label to left of or above the text box it
identifies (I prefer to the left)
Labels and button captions should be 1 to 3 words only,
and appear on one line
Labels and captions should be meaningful
Use sentence capitalization for labels

Microsoft Visual Basic 2010: Reloaded, Fourth Edition

16

Including Graphics and Fonts


in the User Interface

Including Color in the User Interface


Human eye is drawn to color before B&W
Color Guidelines:

Graphics Guidelines:
Human eye is drawn to pictures before text
Include graphics only if necessary
Use for aesthetic purposes
Use to clarify a portion of the screen

Font Guidelines:

Use only one font type for the text in a form


12-point font is easiest to read at high screen resolution
Avoid italics and underlining
Use bold only for titles, headings, and key terms

Microsoft Visual Basic 2010: Reloaded, Fourth Edition

17

Assigning Access Keys

Use color sparingly


Some people have trouble distinguishing colors
What is acceptable in colors is subjective
Color may have specific meaning in certain cultures
Use black or dark text on a white or light background
Use maximum of 3 different colors that complement each
other
Do not use color as the only means of identification

Microsoft Visual Basic 2010: Reloaded, Fourth Edition

18

Assigning Access Keys (continued)

Access key:

Advantages of using access keys:

Allows user to select an object using Alt + access key


Appears underlined on the button caption
Is not case-sensitive
Include & in front of the character to be used as the
access key:

User does not need mouse to navigate and activate


controls
Allows fast typists to keep hands on keyboard
Facilitates use of the application by people with
disabilities

&Calculate Order Calculate Order

Access Key Guidelines:


Assign access keys to each control that can accept user
input

Microsoft Visual Basic 2010: Reloaded, Fourth Edition

19

Microsoft Visual Basic 2010: Reloaded, Fourth Edition

20

Setting the TabIndex Property

User Interface Summary

TabIndex property:
Determines the order in which a control receives the
focus when the Tab key is pressed
Starts at 0
Default TabIndex values are set according to the order
in which the controls were added to the form
When a form starts, the control with the lowest
TabIndex value gets Focus unless Focus is forced to
some other control by the code.

BE CONSISTANT

Focus: the state of being able to accept user input


Microsoft Visual Basic 2010: Reloaded, Fourth Edition

21

Chapter 3
Variables

22

Each variable must be assigned a data type


Data type: the type of data the variable can store
Each data type is a CLASS

Name
Data type
Scope
Lifetime

Microsoft Visual Basic 2010: Reloaded, Fourth Edition

Microsoft Visual Basic 2010: Reloaded, Fourth Edition

Selecting a Data Type for a Variable

Variables: computer memory locations used to


store data (objects) while an application is running
Every variable has a:

Align controls to flow horizontally or vertically


Group related controls visually with white space or
container controls, and maintain consistent margins
Use meaningful labels and captions of 1-3 words
Use graphics and colors sparingly
Use TabIndex property to control where the focus
goes when Tab key is used

A group of instructions used to create an object

23

Microsoft Visual Basic 2010: Reloaded, Fourth Edition

24

Selecting a Name for a Variable


(continued)

Declaring a Variable
Declaration statement: used to declare, or create,
a variable
Declaration statement includes
Scope keyword: Dim or Private or Static
Public
Scope determines Lifetime

Name of the variable


Data type
Initial value (optional)

2010: Reloaded, Fourth Edition


Microsoft Visual Basic 2005:

25

26

Assigning Data to an Existing


Variable

Initializing a Variables
Variables are initialized when they are Instantiated
If you do not provide a value, VB does it for you
VB sets a default value based on data type

Assignment statement:
Used to assign values to properties of controls
Used to assign values to variables

Assignment operator: (=)

Numeric types normally initialized to 0 (zero)


String types set to nothing

Value on the right of the = operator is assigned to the


variable on the left of the = operator

If your code expects variables to be initialized to a


particular value (even if 0) set it yourself in the
declaration

2010: Reloaded, Fourth Edition


Microsoft Visual Basic 2005:

2010: Reloaded, Fourth Edition


Microsoft Visual Basic 2005:

27

2010: Reloaded, Fourth Edition


Microsoft Visual Basic 2005:

28

Assigning Data to an Existing


Variable (continued)

Assigning Data to an Existing


Variable (continued)

String: group of characters enclosed in quotation


marks
Literal constant:
An item of data whose value does not change while the
application is running
Can be a numeric or a string literal constant

A numeric literal with a decimal place is treated as a


Double type. (eg .03)
Literal type character: forces a literal constant to
assume a specific data type (Always use it)
2010: Reloaded, Fourth Edition
Microsoft Visual Basic 2005:

29

30

Using the TryParse Method


(continued)

Using the TryParse Method


Method: a specific portion of a classs instructions
that performs a task for the class
TryParse method:

Assign the TryParse methods return value to a UNIQUE


Boolean variable. (Data Validation)
If True, the conversion was successful
If False, the value could not be converted
Must have an Imports statement in the General Declarations
section of code to use NumberStyles and
NumberformatInfo.CurrentInfo:
Imports System.Globalization

Part of every numeric data types class


Used to convert a string to that numeric data type

TryParse method has either 2 or 4 arguments


String: string value to be converted
NumberStyles (optional): allows formatting
characters to be in the data to be converted
IFormatProvider (optional): specifies formatting
Variable: location to store the result

2010: Reloaded, Fourth Edition


Microsoft Visual Basic 2005:

2010: Reloaded, Fourth Edition


Microsoft Visual Basic 2005:

Line continuation character: the underscore (_)


Breaks up a long instruction into two or more lines
Must appear at end of line, preceded by a space

31

2010: Reloaded, Fourth Edition


Microsoft Visual Basic 2005:

32

Using the Convert Class

Writing Arithmetic Expressions

Convert class:
Contains methods for converting numeric values to
specific data types

Use the dot member access operator to separate


the class name from the method name

2010: Reloaded, Fourth Edition


Microsoft Visual Basic 2005:

33

Writing Arithmetic Expressions


(continued)

Precedence number: indicates the order in which


an operation in an expression is performed
If an expression has two operators with the same
precedence, they are evaluated from left to right
Use parentheses to change the order of evaluation
Consider not relying on precedence and always
use parentheses (precedence rules vary)

2010: Reloaded, Fourth Edition


Microsoft Visual Basic 2005:

34

Writing Arithmetic Expressions


(continued)
Using Parentheses
Should be equal number of open ( and closed )
parentheses in an expression
Write your expression by hand before you code it
Make it part of your Pseudocode

Check your parentheses


Count the # of opens and closes
Evaluate your expression from the inside out

If its too complicated, break up your expression into


multiple expressions, use intermediate variables

2010: Reloaded, Fourth Edition


Microsoft Visual Basic 2005:

35

2010: Reloaded, Fourth Edition


Microsoft Visual Basic 2005:

36

The Scope and Lifetime of a


Variable

The Scope and Lifetime of a


Variable (continued)

Scope: indicates where the variable can be used


Lifetime: indicates how long the variable remains in
memory
Variables are usually declared in one of two places:
Within a procedure
In the forms Declarations section

Procedure-level variable: declared within a


procedure
Procedure scope: only the procedure can use the
variable
2010: Reloaded, Fourth Edition
Microsoft Visual Basic 2005:

37

With procedure-level scope, two procedures can


each use the same variable names
Class scope: variable can be used by all
procedures in the form
Class-level variable:
Declared in the forms Declarations section
Use Private keyword in declaration
Class-level variables retain their values until the
application ends

2010: Reloaded, Fourth Edition


Microsoft Visual Basic 2005:

38

Setting the Focus

Static Variables

Focus method: moves the focus to a specified


control at runtime.

Static variable:
Procedure-level variable that retains its value even
after the procedure ends
Retains its value until the application ends
Can be used instead of a Class-level variable

Most form controls have a Focus method.

A static variable has:


Same lifetime as a Class-level variable
Narrower scope than a Class-level variable

Declared using the Static keyword

2010: Reloaded, Fourth Edition


Microsoft Visual Basic 2005:

39

2010: Reloaded, Fourth Edition


Microsoft Visual Basic 2005:

40

10

Setting the Focus


(continued)

Important Concepts About


Variables and Constants
Variables and named constants are memory
locations that store data
Variables can change value at Runtime, but
constants cannot
Variables and constants have a name, data type,
scope, and lifetime
Use Dim to declare a variable at block or
procedure level
Use Private to declare a variable at Class level

2010: Reloaded, Fourth Edition


Microsoft Visual Basic 2005:

41

Important Concepts About


Variables and Constants
(continued)

42

Additional Concepts About


Variables

Assignment statement is used to assign values to an existing


variable

Assignment Operator is the = sign


Literals are constant items of data
Use the TryParse method to convert a user entered string to
a number
Use the Imports statement to import a namespace
The Convert class contains methods to convert values to a
specified data type. Use to convert datatypes within a
program

2010: Reloaded, Fourth Edition


Microsoft Visual Basic 2005:

2010: Reloaded, Fourth Edition


Microsoft Visual Basic 2005:

43

A procedure-level variable is usable only by the


procedure in which it is declared
A Class-level variable is usable by all procedures
in the form
A block-level variable is usable only within the
block in which it is declared
A static variable is a procedure-level variable that
retains its value when the procedure ends

2010: Reloaded, Fourth Edition


Microsoft Visual Basic 2005:

44

11

Miscellaneous Concepts
Option Explicit On forces declaration of all
variables before use
Option Strict On disallows any implicit type
conversions that may cause a loss of data
Option Infer Off statement: ensures that every
variable is declared with a data type

2010: Reloaded, Second


Fourth Edition
Microsoft Visual Basic 2005:
Edition

45

12

You might also like