44
Chapter 1 1 Intro to Programming and Visual Basic .NET Chapter 1

Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Embed Size (px)

Citation preview

Page 1: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 1

Intro to Programming and Visual Basic .NET

Chapter 1

Page 2: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 2

Program

Set of instructions a computer follows to perform a task

Examples Calculate gross pay, taxes, and net pay Print past-due notices to credit card holders Drop the lowest homework assignment score

Page 3: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 3

Computer Programs

Used in most industries Accounting Human Resources Education Aviation Marketing

Page 4: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 4

Program Acquisition

Shrink-Wrap Software Very available Lower cost Standardized, not customizable

In-house Development Higher cost Customizable to specific needs

Outsourcing Higher cost Customizable

Page 5: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 5

Methods of Programming

Procedural Statements executed by the computer, one

after another, in sequential order from start to termination of a program

Typical of text-based terminal User responds to program

Object-Oriented GUI interface consisting of a set of objects Program responds to user

Page 6: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 6

Procedural Program Example

1. Display onscreen message: "How many hours did you work?"

2. Allow the user to enter the number of hours worked3. Once the user enters a number, store it in memory4. Display onscreen message: “What is your hourly

pay rate?"5. Allow the user to enter an hourly pay rate6. Once the user enters a number, store it in memory7. Multiply the two numbers stored in memory and

store the result in memory8. Display a message on the screen that shows the

gross pay. The message must include the result of the calculation performed in step 7

Page 7: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 7

Procedural Program Example

How many hours did you work? 10

What is your hourly pay rate? 15

Your gross pay is $150.00

C>_

Page 8: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 8

Object-Oriented Programming (OOP)

Centered on object creation. Object: element containing data & actions

Examples Form (window) object Label (descriptions) object Text Box (data entry) object Button (event driven) object

Attributes (Properties) Text property (e.g., Hourly Pay Rate) Size (Height & Width) Location (Vertical & Horizontal Position)

Page 9: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 9

Event-Driven Programming

Responds to events Action or occurrence that takes place in the

program. User Action Examples

Click or double-click a button Press a key on the keyboard

System Occurrences Examples Timer

Sits idle until an event occurs—again program responds to user (or system).

Page 10: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 10

Events

Button Object (Control) responds to a Click event.

Text Box Object (Control) responds to data entry, which is a TextChanged event.

Page 11: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 11

Event Procedure

Algorithm that executes when the event occurs.

Not triggered until event occurs.

Page 12: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 12

Algorithm*

Formula or set of steps for solving a particular problem

Characteristics: Unambiguous Well-defined Clear Fewest steps possible Terminal

*Adapted from webopedia.com’s definition.

Page 13: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 13

Algorithm Example

*Example for algorithm definition on webopedia.com.

Page 14: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 14

Pseudocode*

Outline of a program No real formatting or syntax rules Cross between human language and

programming language. Human readable Basis for algorithm development No real programming language skills needed

*Adapted from webopedia.com’s definition and Gaddis’ definition.

Page 15: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 15

Pseudocode Example

Store hours worked from user input into memory

Store hourly pay rate from user input into memory

Multiply value of hours worked (in memory) by the hourly pay rate (in memory)*

Store result into memory Display result (in memory) as output

*Simple gross pay calculation ignoring overtime rates.

Page 16: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 16

Controls (Objects)

Control Prefix Example Description

Form frm frmMain GUI interface

Button btn btnClose Rectangular object that triggers event procedure when clicked

Label lbl lblGrossPay Box displaying text that user can’t change (descriptions & output)

Text txt txtPayRate Rectangular area for data input by user

Page 17: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 17

Control Prefixes (p. 9)

chk Check Box cbo Combo Box btn Button frm Form grp Group Box

lbl Label lst List Box mnu Menu rad Radio Button pic Picture Box txt Text Box

Page 18: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 18

Download Student Chapter 1 Files

Run Program2\bin\Program2.exe See p. 10

Page 19: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 19

Measures of Quality

Must fulfill users’ needs. Include required functionality. Perform functions correctly.

Should be easy to use with little training. Design for clarity.

Should be understandable looking at coding. Should have flexibility integrated for future

versions of application.

Page 20: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 20

System Development Life Cycle

Involves joint effort of users & programmers.

1. Identify user requirements.

2. Design the application.

3. Construct the application.

4. Implement the system.

Page 21: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 21

Step 1: Identify User Requirements

Review request forms from users. Communicate with users.

Identify current problems & concerns. Determine users’ needs:

Features Method of operation

Obtain contract if you are the outsource for another organization.

Page 22: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 22

Step 1, continued

Clearly define what the program should do.

Purpose To calculate the user’s gross pay.

Input # of hours worked

Hourly pay rate

Process Multiply # of hours worked by the hourly pay rate to obtain gross pay.

Output Display a message indicating the user’s gross pay.

Page 23: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 23

Step 2: Design (Plan) the Application

Create blueprint of application. Sketch components for each user interface,

similar to storyboarding.

Page 24: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 24

Step 2, continued

List needed controls (text boxes, labels, & buttons). Specify properties/attributes (Text) for each control. Specify methods/events (Click) for each control. Write pseudocode &/or flowchart Show design to users & obtain their feedback (very

critical). Revise design based on feedback and continue cycle

of user input.

Page 25: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 25

Step 2 (List Controls Needed)

Type Name DescriptionTextBox txtHoursWorked Allows the user to enter the number of hours worked.TextBox txtPayRate Allows the user to enter the hourly pay rateLabel lblGrossPay Displays the gross pay, after the btnCalcGrossPay

button has been clickedButton btnCalcGrossPay When clicked, multiplies the number of hours worked

by the hourly pay rateButton btnClose When clicked, terminates the application

Page 26: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 26

Step 2 (Define Control Property Values) Property—characteristic, such as control name Value—specific attribute, such as lblGrossPay

Control Type Control Name TextForm (Default) "Wage Calculator"Label (Default) "Number of Hours Worked"Label (Default) "Hourly Pay Rate"Label (Default) "Gross Pay Earned"Label lblGrossPay "$0.00"TextBox txtHoursWorked ""TextBox txtPayRate ""Button btnCalcGrossPay "Calculate Gross Pay"Button btnClose "Close"

Page 27: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 27

Step 2 (List Methods for Controls)

Methods—specific actions to perform based on specific user action, such as mouse click

Method DescriptionbtnCalcGrossPay_Click Multiplies the number of hours worked by the

hourly pay rateThese values are entered into thetxtHoursWorked and txt-PayRate TextBoxesThe result is stored in the lblGrossPay Textproperty

btnClose_Click Terminates the application

Page 28: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 28

Step 2 (Write Pseudocode) Create a pseudocode version of each method:

Pseudocode is a combination of English and a programming language Critical to effect planning; saves valuable time when you start actual programming; minimizes errors as you program. For this application:

Store Number of Hours Worked times Hourly Pay Rate in grossPay.Store the value in grossPay in lblGrossPay.Text.

Page 29: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 29

Step 2 (Continued)

Check the code for errors: Go step by step through the code, running it in your

head as though the computer is running it. Keep track of where in the code is being executed. Keep track of the values of all of the variables.

Page 30: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 30

Begin Program

Input hourly rate

Input # of hours worked

Are the # of hours

> 40?

No

Multiply the hours worked by the hourly rate.

Yes

Multiply 40 by the hourly rate to get the regularly weekly pay.

Subtract 40 from the total hours worked to find the OT hours.

Multiply the pay rate by 1.5 to get the OT rate.

Multiply the OT hours by the OT rate to get the amount of OT pay.

Page 31: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 31

Multiply the hours worked by the hourly rate.

Multiply 40 by the hourly rate to get the regularly weekly pay.

Subtract 40 from the total hours worked to find the OT hours.

Multiply the pay rate by 1.5 to get the OT rate.

Multiply the OT hours by the OT rate to get the amount of OT pay.

Add the regular weekly pay and the OT pay.

Display gross pay

End Program

Page 32: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 32

Step 3: Construct the Application

Use VB to create the application. Create one piece (form) at a time.

Create form (user interface window) and set its properties.

Insert controls based on design specs. Set properties for all controls.

Write code for the event procedures. Use pseudocode to create event procedures

into correct syntax.

Page 33: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 33

Step 3 (continued)

Run the program. Test and debug the application throughout

development. Correct syntax errors, incorrect use of the language,

such as keyword. Correct logic errors, errors that don’t crash the

program but produce inaccurate results, such as adding instead of multiplying.

Use various examples of test data (different numbers, names, etc.).

Page 34: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 34

Getting Started

Create folder on H drive: ISYS1200 Create subfolders w/ in ISYS1200

Practice Assignments Slide Shows

Page 35: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 35

Visual Basic .NET Interface

Start program(see p. 22).

Specify folder and subfolder location (Location text box).

Type program name (Name text box). Chapter1GrossPay MulberyAssignment1

(for assignments)

Folder created within locationbased on project name typed

Page 36: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 36

Project

Numerous files to run program Keep in same folder; do not copy/paste

program files. Can copy/paste image files (bmp) into project

folder if need images

Page 37: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 37

Visual Basic .NET Environment

Mouseover tosee Toolbox

Form(interface)

Design window(displays form)

Form(s) withinSolution Explorer

Property windowfor selected object(currently the form)

Project name

Page 38: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 38

Design Window

Application’s forms Area where you design the interface Grid visible for programmer (not user)

Page 39: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 39

Solution Explorer Window

Solution (container for storing project files)

Page 40: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 40

Properties Window

Displays settings for currently selected object

Changes based on what is selected Currently shows properties for form

object Second example when a Label

control object is selected Note:

Some properties set at Design Time in Properties window.

Other properties set with programming code.

Page 41: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 41

Form Properties

Text Appears on title bar

StartPosition Form location onscreen WindowsDefault (default setting) CenterScreen (typical)

MaximizeBox and MinimizeBox True (Default) False (Dims or hides)

Icon Symbol in top left corner (left of Text property)

Page 42: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 42

ToolBox

Unpinned Pinned (stays onscreen)

Page 43: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 43

Textbook Reference

USE IT—YOU PAID FOR IT!!!! Read information (pp. 16-19). Complete tutorials (pp. 28-29). Answer Check Points (p. 34). Check answers in back of book (p. 819) Note key terms (pp. 36-37) Answer Review Questions (pp. 37-39).

Sometimes these make good test questions! Check answers from ftp site

Page 44: Chapter 11 Intro to Programming and Visual Basic.NET Chapter 1

Chapter 1 44

Reminder

Send e-mail to [email protected] by 5 p.m. today (January 8).