22
Irwin/McGraw-Hill Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San Diego

prepared by James T. Perry University of San Diego

Embed Size (px)

DESCRIPTION

prepared by James T. Perry University of San Diego. Ch. 1: Introduction to VB. Writing windows applications with VB Prog. languages: procedural, object oriented, & event driven Writing VB projects The VB environment Writing your first VB project Finding & fixing errors Visual Basic help. - PowerPoint PPT Presentation

Citation preview

Page 1: prepared by James T. Perry University of San Diego

Irwin/McGraw-HillIrwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc.

PowerPoint® Presentationto accompany

prepared byJames T. Perry

University of San Diego

Page 2: prepared by James T. Perry University of San Diego

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill

Ch. 1: Introduction to VB

Writing windows applications with VB Prog. languages: procedural, object

oriented, & event driven Writing VB projects The VB environment Writing your first VB project Finding & fixing errors Visual Basic help

Page 3: prepared by James T. Perry University of San Diego

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill

Writing Windows Apps. with VB

The Windows GUI

Text boxes

Frame

Labels

Option buttons

Check boxes

Command buttons

Image

Picture box

Page 4: prepared by James T. Perry University of San Diego

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill

Graphic User Interface

Graphic User Interface (GUI) comprises– Forms– Controls– Event-driven programming

Page 5: prepared by James T. Perry University of San Diego

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill

Prog. Languages: procedural, object oriented, & event driven

The Object Model– Objects (nouns) controls– Properties (adjectives) form1.Caption– Methods (verbs) debug.print

Versions of Visual Basic– Working Model– Learning Edition– Professional Edition– Enterprise Edition

Page 6: prepared by James T. Perry University of San Diego

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill

Planning Visual Basic Projects

The three-step process for planning projects– Design the user interface

Sketch the screens with forms and controls needed

– Establish the objects' propertiesWrite down the properties for each object

– Plan the Basic codeWrite out pseudocode for actions your program will

perform

Page 7: prepared by James T. Perry University of San Diego

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill

Writing Visual Basic Projects

The three-step process for writing projects– Design the user interface

Create the forms and controls you previously sketched

– Set the objects' propertiesGive each object a name and set their properties

– Write the Basic codeWrite out Visual Basic code to carry out your

application's actions

Page 8: prepared by James T. Perry University of San Diego

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill

Visual Basic Projects

Visual Basic projects create several files– Project file: .VBP

Holds the names of other files in the project

– Form files: .FRMEach form is saved as a separate fileForm file contains a description of a form's objects

and the Basic code attached to a form

– Standard code module: .BAS (optional)– Custom controls: .OCX (optional)– Form information: .VBW

Page 9: prepared by James T. Perry University of San Diego

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill

The Visual Basic Environment

Form, Project Explorer, Properties, and Form Layout Windows

Toolbox Main Visual Basic window Toolbar, Form location & size information Help Design- , Run- , and Break Time

Page 10: prepared by James T. Perry University of San Diego

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill

The Toolbox

Tool box contents vary based on which version of Visual Basic you are running.

Toolbox contains a common set of tools across all VB versions

Page 11: prepared by James T. Perry University of San Diego

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill

The Visual Basic Toolbar

The buttons on the toolbar are shortcuts Toolbar buttons are a quick way to activate

frequently used commands Each button stands for a command that you

can also select a the Visual Basic menu

Page 12: prepared by James T. Perry University of San Diego

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill

Writing Your First VB Project

Set up your Visual Basic workspace Define user interface Set properties Write code Visual Basic code statements Run, save, open, modify, & print the Hello

World project Documentation

Page 13: prepared by James T. Perry University of San Diego

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill

Set Up Your VB Workspace

Set up Options to reflect these settings:

Page 14: prepared by James T. Perry University of San Diego

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill

Define the User Interface

Resize the form– Drag the lower-right handle to enlarge the form– Drag any handle in the middle of a side to

enlarge the form in that direction only Place controls on the form

– Click the label tool– Click and drag the mouse (a crosshair) to place

the control on the form

Page 15: prepared by James T. Perry University of San Diego

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill

Set Properties

Set the Name and Caption properties– Always set the Name property before writing

code– Next, set the Caption property

The Name property identifies the object internally--so you can refer to it in code

The Caption property externally idenfities an object

Page 16: prepared by James T. Perry University of San Diego

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill

Write Code

You write code enclosed in event procedures, which respond to typical VB events.Private Sub cmdPush_Click() . . . (your code goes here)

End Sub VB automatically supplies the event

procedure Sub/End Sub statements

Page 17: prepared by James T. Perry University of San Diego

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill

Visual Basic Code Statements

Remark statement is any code line beginning with an apostrophe

Assignment statement End statement

Page 18: prepared by James T. Perry University of San Diego

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill

Code the Event Procedures for Hello World

Write the Push event code for the Push Me button (cmdPush)

Write the Push event code for the Exit button (cmdExit)

Page 19: prepared by James T. Perry University of San Diego

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill

Run/Save/Open/Modify the Project

Test the project:– Click Run, Start(or click the Start button on the toolbar)– Click the Push Me button– Click the Exit button

Save the project and the form Make modifications to the form Print the project documentation:

– Form Image, Code, and Form as Text

Page 20: prepared by James T. Perry University of San Diego

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill

Finding & fixing errors

Compile (syntax) errors Run-Time (semantic) errors Logic errors Project Debugging

Page 21: prepared by James T. Perry University of San Diego

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill

Naming Conventions

Objects have special prefixes that help identify the object's general type

Programmers follow the conventions because it simplifies coding and debugging

Never use default names for objects

Page 22: prepared by James T. Perry University of San Diego

Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill

Visual Basic Help

Help includes all of the Microsoft Developer Network (MSDN) library.

The Working Model does not contain the extensive MSDN facilities

Access MSDN online athttp://msdn.Microsoft.com