34
Hands-on Introduction to Visual Basic .NET Programming Right from the Start with Visual Basic .NET 1/e 6

Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Embed Size (px)

Citation preview

Page 1: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Hands-onIntroduction to

Visual Basic.NET

Programming Right from the Start with Visual Basic .NET 1/e

6

Page 2: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 2

Objectives

• Have hands-on experience developing applications with Visual Basic .NET and Visual Studio .NET

• Understand events and their relationships to the graphical user interface

• Explain the advantages of objects for developing applications

Page 3: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 3

Objectives (cont.)

• Understand and effectively use the Button, Label, and PictureBox controls

• Successfully write Windows applications that modify properties at runtime

Page 4: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 4

6-1 What IsVisual Basic .NET?

• VB. NET is a modern development language that shares a syntax heritage with the BASIC language.

• VB. NET maintains Visual Basic’s tradition of excellence as the world’s most widely used tool for developing Windows applications.

Page 5: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 5

6-1 What IsVisual Basic .NET? (cont.)

• VB. NET was completely redesigned to be highly integrated with Microsoft’s .NET Framework.

• VB. NET is a full-fledged object-oriented programming language, making it comparable to C++, Java, Delphi, and C# in terms of developing object-oriented systems.

Page 6: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 6

6-2 Using Visual Studio .NET

• VB .NET applications are developed from within Visual Studio .NET.

• The development environment contains multiple windows and multiple functionalities and is called an integrated development environment (IDE).

Page 7: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 7

6-2 Using Visual Studio .NET (cont.)

Page 8: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 8

6-2 Using Visual Studio .NET (cont.)

• The menubar contains File, Edit and Help plus some other options specific to Visual Studio.

• The standard toolbar gives icon shortcuts for frequently used menu commands.

• The layout toolbar provides icon shortcuts to commands for formatting layouts of forms and other objects.

Page 9: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 9

6-2 Using Visual Studio .NET (cont.)

• The middle of the screen is the Designer window, which contains forms being developed.

• The toolbox located on the left of the screen contains the controls you can add to the form.

• The Solution Explorer on the top right side of the screen typically contains one project, a references folder, an assembly file, and a form file.

Page 10: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 10

6-2 Using Visual Studio .NET (cont.)

• The Properties window on the bottom right side of the screen contains three parts:– Combo box– Properties list– Description pane

Page 11: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 11

6-3 Your First VB. NET Program: Hello World

• Step 1: Add Button to Form

Page 12: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 12

6-3 Your First VB. NET Program: Hello World (cont.)

• Step 2: Set Properties

Page 13: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 13

6-3 Your First VB. NET Program: Hello World (cont.)

• Step 3: Add Code– The Code Editor is where you enter, display,

and edit your code.– A comment is a descriptive note added to the

code for documentation or explanatory purposes.

– An event procedure is code that is called in response to an event, such as a mouse click.

Page 14: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 14

6-3 Your First VB. NET Program: Hello World (cont.)

• Step 3: Add Code (cont.)

Page 15: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 15

6-3 Your First VB. NET Program: Hello World (cont.)

• Step 4: Run the Project

Page 16: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 16

6-3 Your First VB. NET Program: Hello World (cont.)

• Step 5: Save the Project

Page 17: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 17

6-4 Windows GUI

• Visual Basic is the most widely used tool for developing Windows applications.

• Windows applications utilize a GUI that provides visual cues to the user that allow the user to work intuitively and efficiently.

• Windows applications contain WYSIWYG“What You See Is What You Get”

Page 18: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 18

6-5 Working with Objects

• An object is anything we might use in our application for acquiring, manipulating, or presenting data or information.

• An object contains properties (data) and methods (actions for manipulating an object’s data).

• An object is defined once as a class.

Page 19: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 19

6-5 Working with Objects (cont.)

• The developer creates as many instances of the object as necessary for the application.

• The .NET class library is a large library of classes with reusable code included in the Microsoft .NET Framework.

• .NET uses namespaces, which are collections of related classes/– System.Windows.Form is the namespace containing

classes for creating Window based applications.

Page 20: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 20

Reuse and Reliability

• One of the most powerful features of object classes is that they are reusable.

• Objects can enhance reliability, which is the result of good design and lots of testing.– Do not reinvent the wheel

Page 21: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 21

6-6 Control Objects

• The Control class contains numerous properties and methods common to all controls for developing the user interface.

Page 22: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 22

6-6 Control Objects (cont.)

• The Button control is considered to be the most basic graphical control.

• The Label control is used to display text that cannot be edited by the user.

• The PictureBox control is used to display graphics.

• The Timer control is used to raise an event at user-defined intervals.

Page 23: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 23

6-7 Working with Events

• Visual Basic supports event-driven programming in which the application recognizes and responds to events.

• An event is an action or occurrence recognized by some object and for which you can write code to respond.

• And event handler contains code that responds to a particular event.

Page 24: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 24

Event Procedures

• The naming convention for an event procedure is the keyword Sub followed by the name of the triggering object followed by an underscore character followed by the name of the event: e.g.

Sub frmMain_Click

Page 25: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 25

Rem Statement

• Rem statements provide an explanatory remark in a program.

• Header comments occur at the beginning of a project file.

• Block comments appear above a block of one or more lines of code.

• Inline comments typically appear on the same line as a statement.

Page 26: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 26

Rnd Statement

• The Rnd statement generates a single precision random value between 0.0 up to (but not including) 1.0.

• The Randomize statement is used to change the seed value (random sequence).

Page 27: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 27

6-8 Project Development Process

• Analysis stage– The developer decides what kind of application

and features he or she wants.

• Design stage– The developer plans how to achieve the goals

of the analysis stage.

• Implementation stage– When the design is finished, the developer

begins.

Page 28: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 28

6-8 Project DevelopmentProcess (cont.)

• Maintenance stage– Corrective maintenance– Adaptive maintenance– Enhancement maintenance

Page 29: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 29

The Cost of Poor Planning

• Fixing an analysis problem requires 3 times as much time and effort if not fixed until the design stage, 10 times as much time and effort if not fixed until the implementation stage, and 50 to 100 times if not fixed until the maintenance stage.

Page 30: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 30

Testing and Documentation

• Testing and documentation are essential activities for each stage of development.

• Testing at the analysis stage could be a series of “What if…?” questions.

• There is nothing wrong with adding features and functionality, but the developer should be compensated for the additions.

Page 31: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 31

Chapter Summary

• Visual Basic is an object-oriented, event-driven language.

• An object is a self-contained entity that has both properties and methods.

• Windows forms are objects.

• Most of the objects you will need are available in VB. NET.

Page 32: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 32

Chapter Summary (cont.)

• An event refers to an action or occurrence detected by a program.

• An event procedure is the method that handles an event.

• The analysis stage determines what the solution needs to do.

• The design stage determines how the solution will do it.

Page 33: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Crews/Murphy – Programming Right from the Start with Visual Basic.NET 1/e – ©2004 Prentice Hall 33

Chapter Summary (cont.)

• The implementation stage involves writing code to implement the design.

• The maintenance stage begins when the product is delivered.

• Testing and documentation are essential activities of every development stage.

Page 34: Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6

Hands-onIntroduction to

Visual Basic.NET

Programming Right from the Start with Visual Basic .NET 1/e

6