microsoft visual basic 2005: reloaded second edition chapter 1 an introduction to visual basic 2005

63
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Upload: dulcie-maxwell

Post on 16-Jan-2016

234 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded

Second Edition

Chapter 1An Introduction to Visual Basic 2005

Page 2: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 5

Programmers

• Programs: instructions given to computers• Programmers: people who write programs• Applications programmers: write and maintain

programs to handle specific tasks• Systems programmers: write and maintain

programs that run the system, such as operating systems, device drivers, utilities

Page 3: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 9

OOP Terminology

• OOP: Object-oriented programming

• OOD: Object-oriented design

• Object: – Represents a real-world entity– Attributes (or properties): describe the object– Methods: behaviors or operations the object can

perform

• Class: blueprint used to create an object

• Instance: an object created from a class

Page 4: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 13

Visual Studio 2005

• Integrated Development Environment (IDE):– Contains all the tools and features needed to create,

run, and test programs– Includes an editor and compiler

• Visual Studio 2005:– IDE used to create Windows or Web-based programs– Includes Visual Basic 2005, Visual C++ 2005, Visual

C# 2005, and Visual J# 2005

Page 5: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 14

Visual Studio 2005 (continued)

• Application: program or suite of programs

• Windows-based application: – Has a Windows user interface – Runs on a desktop computer

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

Page 6: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 15

Visual Studio 2005 (continued)

• Web-based application: – Has a Web user interface – Runs on a server– Use a computer browser to access it

• Microsoft .NET Framework 2.0: a platform on which you create applications

• .NET languages: the programming languages included in Visual Studio

• .NET applications: applications created with Visual Studio

Page 7: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 16

Visual Studio 2005 (continued)

• .NET Framework class library: – Contains an extensive set of classes for use in .NET

applications– Reduces development time by providing reusable code– Provides consistency among applications

Page 8: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 17

The Common Language Runtime

• .NET language compilers translate program statements into a Microsoft Intermediate Language, also called Intermediate Language (IL)

• Common Language Runtime (CLR):– Manages the execution of IL instructions

• Just-in-time (JIT) compiler: translates IL into machine code

• CLR allows compiled IL to be reused, regardless of which .NET language was used to create it

Page 9: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 18

The Common Language Runtime (continued)

Page 10: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 19

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 part of the solution

Page 11: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 21

Starting Microsoft Visual Studio 2005

Page 12: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 22

Starting Microsoft Visual Studio 2005 (continued)

Page 13: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 23

Starting Microsoft Visual Studio 2005 (continued)

Page 14: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 24

Creating a Visual Basic 2005 Windows-Based Application

Page 15: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 25

Creating a Visual Basic 2005 Windows-Based Application

(continued)

Page 16: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 26

Creating a Visual Basic 2005 Windows-Based Application

(continued)

Page 17: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 27

Managing the Windows in the IDE

Page 18: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 28

The Windows Form Designer Window

• Windows Form Designer window:– Allows you to create (design) the GUI

• Graphical User Interface (GUI): what the user sees and interacts with when using the application

• Windows Form object (or form):– Adds other objects such as buttons and textboxes to

create the GUI – Instance of the Windows Form class– Automatically instantiated when you create an

application

Page 19: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 29

The Windows Form Designer Window (continued)

Page 20: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 30

The Solution Explorer Window

• Solution Explorer window:– Displays a list of projects contained in this solution– Displays the items contained in each project

Page 21: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 31

The Solution Explorer Window (continued)

• Project Designer window:– Open by right-clicking on project folder– Allows you to set options for the project– Contains 9 tabs with groups of options

Page 22: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 32

The Solution Explorer Window (continued)

Page 23: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 33

The Solution Explorer Window (continued)

Page 24: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 34

The Solution Explorer Window (continued)

• Source file: a file containing program instructions

• Code: program instructions

• Form file: a file containing code associated with a Windows form object

Page 25: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 35

The Properties Window

• Properties window: displays properties of selected object

• Default property values are assigned when an object is created

Page 26: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 36

The Properties Window (continued)

Page 27: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 37

The Properties Window (continued)

• Properties window includes an Object box and a Properties list

• Object box:– Located immediately below Properties window title bar– Contains the name of the selected object

• Properties list:– Left column displays names of properties– Settings box: Right column containing the current value

of each property

Page 28: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 38

Properties of a Windows Form Object

Page 29: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 39

Properties of a Windows Form Object (continued)

• Class definition: block of code that defines the attributes and behaviors of an object

• Namespace: defines a group of related classes• Dot member access operator: the period that

separates words in an object’s name• Name property: used to refer to an object in code• Hungarian notation: naming convention using a 3 or

more character prefix to represent the object type• Camel casing: lowercase prefix, uppercase first

letter of each word

Page 30: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 40

Properties of a Windows Form Object (continued)

• Pascal case: – First letter and first letter of each word 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

• StartPosition property: determines the form’s position on the screen when application starts

• Splash screen: first image to appear when application starts

Page 31: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 41

Properties of a Windows Form Object (continued)

Page 32: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 42

The Toolbox Window

• Toolbox: – Contains tools used to create an application– Each tool represents a class from which to instantiate

objects• Controls:

– Objects displayed on a form– Are represented as icons in the toolbox– Can be locked in place on the form – Control names use camel casing

Page 33: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 43

The Toolbox Window (continued)

Page 34: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 44

The Toolbox Window (continued)

Page 35: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 45

The Label Tool

• Label tool: represents a label control• Label control:

– Displays text that user cannot edit– Used as “prompts” to explain controls or display output

Page 36: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 46

The Label Tool (continued)

Page 37: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 47

The Label Tool (continued)

Page 38: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 48

The Button Tool

• Button tool: represents a button control

• Button control:– Performs an immediate action when clicked

Page 39: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 49

The Button Tool (continued)

Page 40: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 50

The Button Tool (continued)

Page 41: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 51

The Code Editor Window

• Events: user actions while program is running

• Event procedure: set of instructions to be executed when an event occurs

• Code editor: used to enter programming code

Page 42: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 52

The Code Editor Window (continued)

Page 43: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 53

The Code Editor Window (continued)

Page 44: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 54

The Code Editor Window (continued)

Page 45: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 55

The Code Editor Window (continued)

• Keyword: has special meaning in a programming language

• Sub procedure: block of code that performs a task

• Event’s Procedure header: – Begins with keyword Private– Procedure name includes object name and event

name– Handles clause indicates for which objects’ events

this code will execute

Page 46: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 56

The Me.Close Method

• Me.Close method: closes the current form

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

• Sequential processing: each line is executed in sequence

Page 47: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 57

The Me.Close Method (continued)

Page 48: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 58

Saving a Solution

Page 49: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 59

Starting and Ending an Application

• Startup form: the form to be displayed when the application starts

Page 50: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 60

Starting and Ending an Application (continued)

Page 51: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 61

Starting and Ending an Application (continued)

Page 52: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 62

Starting and Ending an Application (continued)

Page 53: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 63

Starting and Ending an Application (continued)

Page 54: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 64

Starting and Ending an Application (continued)

• Executable file:– Can be run outside of Visual Studio 2005– Has file extension of .exe

Page 55: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 65

Starting and Ending an Application (continued)

Page 56: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 66

Using an Assignment Statement

• Assignment statement: assigns a value to a variable or property of a control

• Assignment operator: the = symbol

Page 57: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 67

Using an Assignment Statement (continued)

Page 58: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 68

Using an Assignment Statement (continued)

Page 59: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 69

Printing Your Code

Page 60: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 70

Closing the Current Solution

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

Page 61: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 71

Closing the Current Solution (continued)

Page 62: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 72

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

Page 63: Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 1 An Introduction to Visual Basic 2005

Microsoft Visual Basic 2005: Reloaded, Second Edition 73

Opening an Existing Solution (continued)