Top Banner
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Microsoft Visual Basic 2015: Reloaded Sixth Edition Chapter One An Introduction to Visual Basic 2015
67

Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

Apr 13, 2018

Download

Documents

vuongnga
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: ReloadedSixth Edition

Chapter One

An Introduction to Visual Basic 2015

Page 2: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

2

Objectives

After studying this chapter, you should be able to:

• Define some of the terms used in object-oriented programming

• Create, start, and end a Visual Basic 2015 Windows application

• Manage the windows in the integrated development environment (IDE)

• Set the properties of an object

• Manipulate controls

Page 3: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

3

Objectives (cont’d.)

• Use label, button, and picture box controls

• Use the options on the FORMAT menu

• Write Visual Basic code

• Save, close, and open a solution

• Run a project’s executable file

• Write an assignment statement

• Print an application’s code and interface

• Find and correct a syntax error

Page 4: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Visual Studio 2015

• Visual Basic 2015 is an object-oriented programming language (OOP)

• Object: anything that can be seen, touched, or used

• Class: a pattern used to create an object

• Instance: an object created from a class; object is said to be instantiated

• Integrated Development Environment (IDE):

• Contains all the tools and features needed to create, run, and test programs

• Download a free copy at www.microsoft.com/visualstudio/eng/downloads

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

4

Page 5: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

5

Visual Studio 2015 (cont'd.)

• Application: program or suite of programs

• Windows-based application:

• Has a Windows user interface

• Runs on a personal computer

• User interface: what the user sees and interacts with when using an application

• Web-based application:

• Has a Web user interface

• Runs on a server

• Accessed with a computer browser

Page 6: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

6

Starting and Configuring Visual Studio

Figure 1-1: How to start Visual Studio Community 2015

Page 7: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

7

Starting and Configuring Visual Studio(cont’d.)

Figure 1-2: How to configure Visual Studio Community 2015

Page 8: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

8

Starting and Configuring Visual Studio(cont’d.)

Figure 1-3: Options dialog box

Page 9: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

9

Starting and Configuring Visual Studio(cont’d.)

Figure 1-4: Microsoft Visual Studio Community 2015 startup screen

Page 10: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

10

Creating a Visual Basic Windows Forms Application• Windows applications consist of solutions,

projects, and files

• Solution: a container that stores projects and files for an entire application

• Project: a container that stores files associated with a specific portion of the solution

• A solution may contain one or more projects

Page 11: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Creating a Visual Basic Windows Forms Application (cont’d.)

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

11Figure 1-5: How to create a Visual Basic 2015 Windows application

Page 12: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Creating a Visual Basic Windows Forms Application (cont’d.)

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

12Figure 1-6: New Project dialog box

Page 13: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Creating a Visual Basic Windows Forms Application (cont’d.)

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

13

Figure 1-7: Solution and Visual Basic Project

Page 14: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Creating a Visual Basic Windows Forms Application (cont’d.)

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

14Figure 1-8: How to manage the Windows in the IDE

Managing the Windows in the IDE

Page 15: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Creating a Visual Basic Windows Forms Application (cont’d.)• The Windows Form Designer Window

• Allows you to create (design) the GUI

• Graphical user interface (GUI):

• What the user sees and interacts with

• Windows Form object (or form):

• Foundation for the user interface

• Add other objects such as buttons/text boxes to form

• Title bar with caption and Minimize, Maximize, and Close buttons

• Tab at top of designer window has Form1.vb [Design]

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

15

Page 16: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Creating a Visual Basic Windows Forms Application (cont’d.)

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

16

Figure 1-9: Windows Form Designer window

Page 17: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

17

Creating a Visual Basic Windows Forms Application (cont’d.)• The Solution Explorer Window

• Displays a list of projects contained in this solution

• Displays the items contained in each project

Figure 1-10: Solution Explorer window

Page 18: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

18

Creating a Visual Basic Windows Forms Application (cont’d.)• Source file

• A file containing program instructions

• Code

• Program instructions

• Form file

• A file containing code associated with a Windows form

• Give each form file a meaningful name using the Properties window

Page 19: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

20

Creating a Visual Basic Windows Forms Application (cont’d.)

• The Properties Window

• Properties

• A set of attributes that determine an object’s appearance and behavior

• Properties window• Displays properties of the selected object

• Default property values are assigned when an object is created

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

Page 20: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

21

Creating a Visual Basic Windows

Forms Application (cont’d.)

Figure 1-11: Properties window

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

Page 21: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Properties of a Windows Form

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

21

Figure 1-12: Partial list of the form’s properties

Page 22: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

22

Properties of a Windows Form (cont'd.)

• Class definition• Block of code that defines the attributes and behaviors

of an object

• All class definitions are contained in namespaces

• Namespace: • Defines a group of related classes

• Dot member access operator• The period that separates words in an object’s name to

indicate a hierarchy of namespaces

Page 23: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

23

Properties of a Windows Form (cont'd.)

• Name and Text Properties• Assign meaningful names to forms and use a naming

convention

• Pascal case• First letter of each word in the name is uppercase

• First part of name is object’s purpose

• Second part of name is object’s class

• Text property• Controls the caption displayed on form’s title bar

Page 24: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

24

Properties of a Windows Form (cont'd.)

• StartPosition property• Determines the form’s position on the screen when

application starts

• Font Property• General shape of characters in text

• Recommended font is Seqoe UI font

• Size Property

• Two numbers separated by a comma and a space

• The first number represents the object’s width, and the second number represents its height

Page 25: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

25

The Toolbox Window

• Toolbox• Contains objects that can be added to other objects,

such as a form

• Each tool has an icon and a name to identify it

• Each tool represents a class from which objects, called controls, can be created

• Controls• Objects displayed on a form

• Represented as icons in the toolbox

• Controls on a form can be selected, sized, moved, deleted, locked in place on the form and unlocked

Page 26: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

26Figure 1-13: Toolbox window

The Toolbox Window (cont’d.)

Page 27: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

The Toolbox Window (cont'd.)

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

27Figure 1-14: How to add a control to a form

Page 28: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

The Toolbox Window (cont'd.)

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

28

Figure 1-15: How to manipulate the controls on a form

Page 29: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

29

The Toolbox Window (cont'd.)

Figure 1-16: Olivia application’s user interface

Page 30: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

30

The Toolbox Window (cont’d.)

• Label control:• Displays text that user cannot edit

• Used as “prompts” to explain controls or display output

• Name should end with “Label”

• Control names use camel case

• Camel case: • Lowercase first word; uppercase first letter of each

subsequent word in the name

• Not necessary to assign meaningful names for labels used as prompts because they are never used in code

• Labels used for output should have meaningful names

Page 31: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

31

The Toolbox Window (cont’d.)

• Button control

• Performs an immediate action when clicked

• Its name should end with “Button”

• Picture Box Control

• Displays an image on the form

Page 32: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Using the Format Menu• Format menu:

• provides options for manipulating controls on the form

• First control selected is the reference control

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

32

Figure 1-17: How to use the Format menu to align/size/center controls

Page 33: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

The Code Editor Window

• Events:

• User actions while program is running

• Examples: clicking, double-clicking, scrolling

• Event procedure:

• Set of instructions to be processed when an event occurs

• Tells the object how to respond to an event

• Code Editor window:

• Used to enter event procedure’s code

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

33

Page 34: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

The Code Editor Window (cont'd.)

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

34

Figure 1-18: How to open the Code Editor window

Page 35: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

35

The Code Editor Window (cont’d.)

• Class statement

• Used to define a class

• Syntax

• Rules of the language

Figure 1-19 Code Editor window

Page 36: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

The Code Editor Window (cont'd.)

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

36

Figure 1-20: Code template for the exitButton’s Click procedure

Page 37: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

37

The Code Editor Window (cont'd.)

• Procedure header

• First line in the code template

• Handles clause indicates for which objects’ events this code will execute

• Procedure footer

• Last line in the code template

• Keyword

• A word with special meaning in a programming language

• Sub procedure

• Block of code that performs a task

Page 38: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

38

The Code Editor Window (cont'd.)

• Me.Close() instruction

• Closes the current form at run time

• If the current form is the only form, the application is terminated

• Me keyword: refers to the current form

• Method

• Predefined VB procedure that can be invoked (called) when needed

• Sequential processing

• Each line is executed in sequence

• Also called a sequence structure

Page 39: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

39

The Code Editor Window (cont'd.)

Figure 1-21: Me.Close() instruction entered in the Click event procedure

Page 40: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

40

Saving a Solution

• An asterisk (*) appears on the designer and Code Editor tabs if a change was made since the last time the solution was saved

Figure 1-22: How to save a solution

Page 41: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

41

Starting and Ending an Application• Startup form

• The form to be displayed when the application starts

Figure 1-23: How to specify the startup form

Page 42: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Starting and Ending an Application (cont'd.)

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

42

Figure 1-24: Project Designer window

Page 43: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

43

Starting and Ending an Application (cont'd.)

Figure 1-25: How to start an application

Page 44: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

44

Starting and Ending an Application (cont'd.)

Figure 1-26: Result of starting the Olivia application

Page 45: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

45

Starting and Ending an Application (cont'd.)

• When you start a VB application, the IDE creates an executable file

• Executable file

• Can be run outside of Visual Studio 2015

• Has a file extension of .exe

• Stored in the project’s bin\Debug folder

Page 46: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

46

Starting and Ending an Application (cont'd.)

Figure 1-27: How to change the executable file’s name in the Project Designer window

Page 47: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

47

Starting and Ending an Application (cont'd.)

Figure 1-28: How to end a running application

Page 48: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

48

Assigning a Value to a Property During Run Time• Properties window

• Used to set property values at design time

• Assignment statement

• Assigns a value to a variable or property of a control

• Used to set property values at run time

• String

• Zero or more characters enclosed in quotation marks

• Assignment operator

• the = sign

• Value of expression on the right of the = sign is assigned to the object and property on the left of the = sign

Page 49: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

49

Assigning a Value to a Property During Run Time (cont’d.)

Figure 1-29: How to assign a value to an object’s property during run time

Page 50: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

50

Figure 1-30: Assignment statements entered in the Code Editor window

Assigning a Value to a Property During Run Time (cont’d.)

Page 51: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Printing the Code and User Interface

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

51

Figure 1-31: How to print the code and interface during design time

Page 52: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

52

Closing the Current Solution

• Closing a solution closes all projects and files in that solution

• You are prompted to save any files that have unsaved changes

Figure 1-32: How to close a solution

Page 53: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

53

Opening an Existing Solution

• Only one solution can be open at any one time

• If a solution is already open, opening a different one will close the currently open solution

Figure 1-33: How to open an existing solution

Page 54: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Syntax Errors• Bug

• An error in a program’s code

• Debugging

• The process of locating and correcting bugs in a program

• Syntax error

• Occurs when you break one of the programming language’s rules

• Most syntax errors are caused by typing errors

• Rest the mouse pointer on the mistyped instruction to see details about the error

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

54

Page 55: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Syntax Errors (cont’d.)

• Syntax errors should be corrected before starting an application

• If you start an application with a syntax error, a dialog box appears

• Click No to open the Error List window

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

55

Page 56: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

56

Syntax Errors (cont’d.)

Figure 1-34: Syntax error in the exitButton’s Click procedure

Figure 1-35: Result of placing the mouse pointer on the jagged blue line

Page 57: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

57

Syntax Errors (cont’d.)

Figure 1-36: Message dialog box

Figure 1-37: Result of starting an application that contains a syntax error

Page 58: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Programming Tutorial 1

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

58

Figure 1-55: Correct size for the picture box

Page 59: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Programming Tutorial 2

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

59Figure 1-65: Sample run of the Cake Shoppe application

Page 60: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Programming Example

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

60

Figure 1-67: User interface

Page 61: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Summary• Object-oriented programming language allows

programmers to use objects to accomplish a goal

• Object: can be seen, touched, or used and has attributes that control its appearance and behavior

• Class: a pattern from which an object can be created

• Applications created in Visual Studio 2015 are composed of solutions, projects, and files

• Windows Form Designer window: used to create GUI applications

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

61

Page 62: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Summary (cont'd.)

• A form is the foundation for the user interface

• Windows Form object is instantiated from the Windows Form class

• Solution Explorer window: displays names of projects and files in the solution

• Properties window: lists an object’s properties

• All class definitions are contained in namespaces

• System.Windows.Forms namespace contains definition of the Windows Form class and class definitions for objects added to a form

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

62

Page 63: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Summary (cont'd.)

• Name property: used to refer to an object in code

• Text property of a form: specifies the text to be displayed in the title bar of the form and in the taskbar when running

• Form’s StartPosition property sets the position of the form when it first appears at run time

• Recommended font is Segoe UI in 9-point size

• Toolbox: contains tools for creating the GUI

• A control’s Text property value is displayed inside the control

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

63

Page 64: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Summary (cont'd.)

• Controls on a form can be selected, sized, moved, deleted, restored or locked or unlocked

• Label control: contains text that a user cannot edit

• Identifying label’s BorderStyle and AutoSize properties are usually set to None and True

• A label control that displays program output, usually has its BorderStyle and AutoSize properties set to FixedSingle and False

• Button control: performs an immediate action when clicked

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

64

Page 65: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Summary (cont'd.)

• Picture box control: displays an image on a form

• Format menu provides options for aligning and sizing controls on a form

• Event procedure: the code that tells an object how to respond to an event

• Format menu provides options for aligning and sizing controls on a form

• Event procedure: the code that tells an object how to respond to an event

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

65

Page 66: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Summary (cont'd.)

• Use the Class Name and Method Name list boxes to select an object and event to code

• Code Editor: provides code templates for each object’s event procedures

• Me.Close() instruction: can terminate an application

• You should save the solution every 10 or 15 minutes

• Computer automatically creates an executable file when you start a Visual Basic application in the IDE

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

66

Page 67: Microsoft Visual Basic 2015: Reloaded - irsccsdept.org · Visual Studio 2015 •Visual Basic 2015 ... (IDE): •Contains all the tools and features needed to create, run, ... Microsoft

© 2016 Cengage Learning®. May not be scanned, copied

or duplicated, or posted to a publicly accessible website, in

whole or in part.

Summary (cont'd.)

• Use an assignment statement to assign a value to a property during run time

• You should print your application’s code and its user interface

• Closing a solution closes all projects and files in it

• The process of locating and correcting errors (bugs) in a program is called debugging

Microsoft Visual Basic 2015: Reloaded, Sixth Edition

67