48
IS 118 1 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

  • View
    215

  • Download
    0

Embed Size (px)

Citation preview

Page 1: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 1

IS 118 Introduction to Development Tools

VB Chapter 01-02

Page 2: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 2

Things to Cover

What is Visual Basic – (VB) How it operates vs. Others Sound Program Criteria

Chapter 2 The IDE Forms, and Controls Events, properties and methods Coding and Naming conventions Running Executables

Page 3: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 3

Note

For These chapters we will follow the book and you should follow along on your computer as we do it

Page 4: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 4

Evolution of Visual Basic

Evolved from BASIC (Beginner’s All-Purpose Symbolic Instruction Code) Designed to provide interactive computing on

mainframe computersWidely available on early microcomputersIntroduction of personal computers (early

1980’s) Microsoft introduced GW-Basic with the DOS

operating system

Page 5: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 5

Language Processors

Required to process programs into a program the computer can understand

Interpreters Read, interpret, and carry out one line of code at a time

Compilers Translate a source program (i.e. one written in VB) Create an object program (one a machine can read)

Object programs also called “executables” Compiled programs run much faster

Page 6: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 6

Characteristics of Visual Basic Provides visual objects (controls) that can be

drawn onto a window (form) Makes building the interface much easier

Object-oriented code structure Code structured around objects

Easy to understand syntax “IntelliSense” technology helps write code

Objects can be reused and extended through inheritance

Event-driven language Things happen in response to events

Examples of events: mouse click, opening or closing a window

The user, not the program determines the sequence of operations

Page 7: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 7

Creating a VB Program

Takes place in the Visual Studio Integrated Development Environment (IDE) Provides an environment for creating the interfaces,

writing and testing code, and making changes Provides the .NET framework for Web services, Visual

C#.NET, Visual Basic.NET, etc.

Statement: an instruction that can stand alone Code: a group of statements

Page 8: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 8

Overview of VB Program DevelopmentCriteria of a sound application

Internal criteria geared to the programmer External criteria geared to the user

Program development cycle Understand distinct steps in the process of

developing an application

Page 9: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 9

External Criteria Functionality

Does the program do what it is supposed to do?

Efficiency Program should minimize the use of computer

resources Includes memory, processing time, and storage

space

User-Friendliness Make the application easy to use

Includes helpful error messages, guarding against user errors, consistent appearance and behavior of windows

Page 10: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 10

Internal Criteria Consistency in coding style

Following conventions most programmers follow Indenting blocks of code Naming objects with predefined prefixes

Code clarity and readability Use meaningful variable names Adding comments to code can aid understanding

Modularity in code design Each block of code is isolated from the rest of the

program Easier to debug, review, and revise

Page 11: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 11

Internal Criteria

Elegant algorithms Algorithm: a systematic approach to solving the

programming problem Logic easy to trace and implement Efficient in terms of speed and storage

requirementsCode maintainability

General applicability: code will not require revision even if the program requirements change

Page 12: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 12

Steps in Developing a Program

Developing an application requires several distinct steps

Skipping or not giving careful attention to steps can create a lot of rework, headaches, and expense Mistakes made in the earlier stages of program

development require much more time, money, and hassle to rework

Page 13: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 13

Steps in Program DevelopmentAnalyze and define the problem

Program must meet application needs

Design the visual interface Decide what data fields appear and the

appropriate controls

Define User-Program Interaction Define events, both user actions and system

activities

Page 14: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 14

Steps in Program Development

Design the code structure Structure dictated by responses program

should carry out Well-designed code enhances maintainability

Write Code Develop code based on your analysis of the

problem and design of the structure

Page 15: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 15

Steps in Program Development

Test and edit the program Various error types:

Syntax errors: failure to follow programming rules Semantic errors: failure to say what you mean Logic errors: difference between what programmer

thinks code will do and what it actually does

Place the program into production Production program works with live data and

produces “real” results

Page 16: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 16

Learning the Language

Comparing learning a spoken language and learning a programming language

Vocabulary Types of objects, methods, and events

Grammar Syntax rules

Semantics Meaning of how programming constructs fit together

Effectiveness Finding better ways to express the same idea

Page 17: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 17

Hands-on Practice

Programming is a skill, like playing a sport or a musical instrument

Practice enables you to gain familiarity with: The IDE The vocabulary and syntax rules of VB How different parts of the code fit together Identify opportunities for code improvement

Page 18: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 18

The IDE –lets do it

Page 19: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 19

Summary

Visual Basic evolved from BASICVisual elements allow easy changes in

user interfaceObject-oriented syntax makes it easier

to learn vocabulary and syntaxObject-oriented language enhances

code reusability Inheritance allows programmer to reuse code

Page 20: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 20

Summary

Sound programs must meet internal criteria and external criteria

There are distinct steps in developing code. Don’t try to shortcut the early stages

Learning a programming language is like learning a spoken language

PRACTICE, PRACTICE, PRACTICE

Page 21: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

Copyright (c) 2003 by Prentice Hall

Chapter 2Introduction to Visual Basic

Programming

Visual Basic.NET

Page 22: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 22

Objectives

Navigate the IDECreate controls on a form and adjust their

sizesUnderstand the events, properties, and

methods of controlsUnderstand how the code and events work

in a VB program

Page 23: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 23

Objectives

Open and save a VB projectUnderstand the coding mechanics and the

naming conventionGet help from the MSDN help systemEnumerate the types of statements in a

programRun an executable without the IDE

Page 24: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 24

The IDE Profile

Page 25: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 25

Starting the IDE

The Visual Studio Start Page

Page 26: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 26

Starting a New ProjectDefault: Windows Application

Page 27: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 27

The Integrated Development Environment (IDE) Menu bar provides many menu items

Examples include File and Edit menus

Toolbar lies below menu bar Provides shortcuts to the menu bar

Toolbox Contains various icons representing VB controls

Solution Explorer Shows all forms, references, classes, and modules the

current project contains

Page 28: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 28

The IDEMenu bar

Toolbar

Blank form in IDE

Toolbox

Page 29: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 29

Solution Explorer and Properties Window

Solutions Explorer shows all the forms, references, classes, and modules in the project

Properties window shows all the properties of the selected object

Page 30: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 30

Your First Visual Basic Program

Form contains a label and a button

Double-click the button on the form to open the code window

Page 31: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 31

The Code Window

Tabs at top let you toggle between the form and the code window

Comments appear green in the IDEObject-oriented syntax: object

and property separated by dot (period)

Procedure box lists events the object in the object box recognizes

Object box lists all objects in the form

Page 32: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 32

When You Run the Program

Label changes when you click the Say Welcome button

Page 33: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 33

Understanding the IDE

Design time When you are placing controls on the form When you are writing code in the code window

Runtime When the code in your project comes to life,

responding to events Press Start on the Debug menu in the IDE Press the F5 key in the IDE Press the start button in the IDE

Page 34: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 34

Coding Mechanics

Comments Used to provide clues to the purpose of the code Begin with tick mark (apostrophe) or Rem Appear green in the IDE

Showing Blocks of Code The IDE will help indent the code lines

Line Continuation If you have to write a long statement, break into lines by

using the underscore (_) character

Page 35: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 35

Interfaces of VB Objects

Forms and controls are objectsObjects have interfaces:

Properties: typically relate to appearance of objects

Events: user or system actions recognized by the object

Procedures written to handle events Methods: actions that objects are capable of

performing

Page 36: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 36

PropertiesSpecial types of data associated with

objectMost relate to appearance of objects

i.e. Label1.BackColor = Color.Red

Some relate to behavior of objects i.e. btnNext.Enabled – True

Object and property separated by dot (period)

Property must be given a value

Page 37: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 37

EventsUser or system actions the object

recognizes i.e. a button has a Click event

Event procedure Procedure written to handle a specific event Also called event handler

Syntax: Private Sub ObjectName_Event Code surrounded by Sub … End Sub Private refers to the scope of the procedure Object and event separated by underscore

Page 38: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 38

Methods

Actions objects are capable of performing i.e. Me.Close()

Syntax: Object.Method(Parameter List) Parameter list: arguments passed in to the

method Parameter list must be enclosed in

parentheses, even if no parameters are required

Page 39: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 39

Getting Help from the Help Menu

Enter search term in the Look for box

Double-click an item in the list box

Double-click an item in the lower center pane; upper center pane shows results

Page 40: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 40

Naming objects

When naming objects, be descriptive Use standard prefixes, i.e. lbl for label Give the object a meaningful name

i.e. a label with text “Name” could be lblName

Change the object name in the Properties window

Name objects before placing code in the code window

Page 41: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 41

Assignment Statements

Generate some sort of result i.e. moving data from one location in memory to

another

Syntax: lblWelcome.Text = “Welcome” Expression on right hand side of equation

moved to memory location on left hand side

Most common statements in VB programs

Page 42: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 42

Statements That Direct Execution Flow Conditional Execution

One block of code executed if a statement is true; a different block executed if false

If block is most common example

Repetition When you need to execute a block of code repetitively For…Next loop is most common

Code that “Jumps” Exit Sub exits a procedure

Page 43: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 43

Completing the Development CycleProgram must be compiled into executable

When you test run your program, the IDE compiles and saves the executable

To run the program: Double-click the executable Use the Run option off the Start menu Add the executable to your Start menu

Page 44: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 44

Finding the Executable

Executable is found in the /bin folder underneath the folder containing your project.

In this case: C:\My Documents\ Visual Studio Projects\Welcome

Page 45: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 45

Summary Start the IDE from the Start Menu

Choose Visual Studio.NET from Programs menu

Edit your profile to customize environment Menu bar gives you all menu items. Toolbar

offers shortcuts to menu items Toolbox contains controls and components The form allows you to design visual elements

Code window behind form is where you place code

Solution Explorer shows all files in your solution

Page 46: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 46

Summary Properties window shows properties of selected

object To develop a program

Draw and adjust the controls on the form Set properties of the objects Place code in events, then test and revise

The IDE allows you to write and compile the program

Use comments in your code to show the purpose of the code

Break long code lines with an underscore character

Page 47: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 47

Summary

Objects have three types of interfaces: properties, methods, and events

VS.Net help file provides a wealth of information Follow object naming conventions

Use predefined prefixes for objects Give objects meaningful names

Two types of programming statements: Those that produce results Those that control program flow

Page 48: IS 1181 IS 118 Introduction to Development Tools VB Chapter 01-02

IS 118 48

Summary

Four types of objects introduced: Form used for visual interface Label used to display text to give clues Button used to trigger actions Timer used to keep track of time

IDE automatically produces the executable when you develop the program

Run the executable like other Windows programs