Date post: | 04-Jan-2016 |
Category: |
Documents |
Upload: | leslie-lindsey |
View: | 214 times |
Download: | 0 times |
COPYRIGHT 2007: Dr. David Scanlan, CSUS
010-HELLO WORLD VB-Express.ppt Purpose: A "Hello World" program's purpose is to eliminate as much complexity as possible so that students successfully write and run their first program. What these slides cover: --How to write a simple program. --How to reduce the complexity of the IDE --How to place objects on a form --How to use the Toolbox --How to use a Textbox for output --How to use a Button --How to run a program --How to save a program
010-HELLO WORLD VB-Express.ppt
Slide 1- 1
COPYRIGHT 2007: Dr. David Scanlan, CSUS
OBJECTIVES:• To get started immediately so that you get the "big" picture right away.
• This will make VB 2008.NET textbook easier to understand.• To reduce the complexity of the IDE.
• IDE: Integrated Development Environment.• To quickly show how easy it is to write a simple program in VB 2008.NET.• The program will illustrate:
• the use of the Toolbox,• the use of a Textbox for output.• the use of a Button,• and the output of the words "Hello World" in a Textbox when a
button is pressed.• To learn how to save a program.
FIRST PROGRAM: HELLO WORLD VB Express
Slide 1- 2
COPYRIGHT 2007: Dr. David Scanlan, CSUS
NOTE:This program uses the default names for your button, label, textbox and form: button1, label1, textbox1 and form1.
These names were not changed in order to make the following program as simple as possible.
Later, we will make the names of buttons, labels, etc much more meaningful.
FIRST PROGRAM: HELLO WORLD VB Express
Slide 1- 3
COPYRIGHT 2007: Dr. David Scanlan, CSUS
Dr. Scanlan: Program this with the class following. Use 18 point font for the code.
HELLO WORLD PROGRAM
LABEL
TEXTBOX
BUTTON: Press the button and "Hello World appears in the LABEL and in the TEXTBOX.
COPYRIGHT 2007: Dr. David Scanlan, CSUS
FIRST PROGRAM: HELLO WORLD VB ExpressRequirements
When you start VB Express, the Screen will look like this.
Click here to create a Project (a program)
Slide 1- 5
COPYRIGHT 2007: Dr. David Scanlan, CSUS
FIRST PROGRAM: HELLO WORLD VB Express
Select this
This is not a very meaningful name for the Project.See next slide.
Slide 1- 6
COPYRIGHT 2007: Dr. David Scanlan, CSUS
FIRST PROGRAM: HELLO WORLD VB Express
Hello World is a much more meaningful name for this Project.
Enter Hello World here.
Next, press OK
Slide 1- 7
COPYRIGHT 2007: Dr. David Scanlan, CSUS
FIRST PROGRAM: HELLO WORLD VB Express
Your Screen should now look like this.
Click on Data Sources. We are going to get if off the screen because we will not be using it in this course.
Slide 1- 8
COPYRIGHT 2007: Dr. David Scanlan, CSUS
FIRST PROGRAM: HELLO WORLD VB Express
Your screen should now look like this.
Click on the “x” to get the Data Source window off the screen.We did this to simplify the IDE (Integrated Development Environment.
Slide 1- 9
COPYRIGHT 2007: Dr. David Scanlan, CSUS
FIRST PROGRAM: HELLO WORLD VB Express
Your screen should now look like this.
We will use these two windows a lot during this semester.1. Solution Explorer Window2. Properties Window
Slide 1- 10
COPYRIGHT 2007: Dr. David Scanlan, CSUS
FIRST PROGRAM: HELLO WORLD VB Express
Place the cursor on the Toolbox Tab to cause the tools to be displayed.
Note: If you move the cursor away from the Tab, the tools will disappear. Only the Tab will remain.
You can keep the Toolbox in view if you click on the horizontally oriented pin.See next slide.
Slide 1- 11
COPYRIGHT 2007: Dr. David Scanlan, CSUS
FIRST PROGRAM: HELLO WORLD VB Express
Note the vertical orientation of the pin.The Toolbox is now “pinned down”.
Slide 1- 12
COPYRIGHT 2007: Dr. David Scanlan, CSUS
FIRST PROGRAM: HELLO WORLD VB Express
Next, select a Button from the ToolBox and place it on the form.There are two ways to place a Button on the form:
1. Double Click on the Button.2. Click on the Button and drag it onto the form.
Slide 1- 13
COPYRIGHT 2007: Dr. David Scanlan, CSUS
FIRST PROGRAM: HELLO WORLD VB Express
Place the button about here
Next, place a Textbox on the form using the same procedure you used for the Button.
Slide 1- 14
COPYRIGHT 2007: Dr. David Scanlan, CSUS
FIRST PROGRAM: HELLO WORLD VB Express
The form should now look like this.
Form
Button
Textbox
Note: a Textbox can be used to display data or to input data into the program.
Slide 1- 15
COPYRIGHT 2007: Dr. David Scanlan, CSUS
FIRST PROGRAM: HELLO WORLD VB Express
Double click on the button to produce a “Click Event” in the code view where we do our code programming.
See next slide.
Slide 1- 16
COPYRIGHT 2007: Dr. David Scanlan, CSUS
FIRST PROGRAM: HELLO WORLD VB Express
Your screen should now look like this.
We will place our code here.
See next slide.
Slide 1- 17
COPYRIGHT 2007: Dr. David Scanlan, CSUS
FIRST PROGRAM: HELLO WORLD VB Express
Object
Property
Data
Code View Tab Design View Tab
Now run the program by pressing here.
See next slide.
Slide 1- 18
COPYRIGHT 2007: Dr. David Scanlan, CSUS
FIRST PROGRAM: HELLO WORLD VB Express
Your program should now look like this.
Next, press the button and watch “Hello World” get displayed in the Textbox.
Slide 1- 19
COPYRIGHT 2007: Dr. David Scanlan, CSUS
FIRST PROGRAM: HELLO WORLD VB Express
After pressing the button while the program is running, Hello World is displayed in the Textbox.
Slide 1- 20
COPYRIGHT 2007: Dr. David Scanlan, CSUS
FIRST PROGRAM: HELLO WORLD VB Express
An easy way to stop the program is to press the “x”
Slide 1- 21
COPYRIGHT 2007: Dr. David Scanlan, CSUS
FIRST PROGRAM: HELLO WORLD VB Express
An easy way to exit Visual Basic 2008 Express is to press this “x”
Slide 1- 22
COPYRIGHT 2007: Dr. David Scanlan, CSUS
FIRST PROGRAM: HELLO WORLD VB Express
If you want to save your Project, then choose Save.
Slide 1- 23
COPYRIGHT 2007: Dr. David Scanlan, CSUS
FIRST PROGRAM: HELLO WORLD VB Express
Project name
Solution NameSolution files can contain several projects. In this course we will have only one project.
I would change the location to something easy to remember.
How about C:\MIS 15?See next slide.
Slide 1- 24
COPYRIGHT 2007: Dr. David Scanlan, CSUS
FIRST PROGRAM: HELLO WORLD VB Express
Slide 1- 25
COPYRIGHT 2007: Dr. David Scanlan, CSUS
FIRST PROGRAM: HELLO WORLD VB Express
Your project has now been saved on your hard drive:
C:\MIS 15\Hello World
Take a look, it is there.
Slide 1- 26
HELLO WORLD PROGRAM
LABEL
TEXTBOX
Add a LA
BEL just for practice
COPYRIGHT 2007: Dr. David Scanlan, CSUS
FIRST PROGRAM: HELLO WORLD VB Express
Congratulations! You just wrote your first Visual Basic 2008 Program.
Slide 1- 28
How to Reset the IDEback to the original settings.
Slide 1- 29
If your IDE looks like this and you want to resetit. Follow the next slides…
Slide 1- 30
Click here.
Slide 1- 31
Click here.
Slide 1- 32
Click here.
Slide 1- 33
Click here.
Slide 1- 34
Click here.
Slide 1- 35
The IDE has been restored to its original settings.Note: The Data Sources Tab is now present.
The EndSlide 1- 36
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
STARTING OUT WITH
Visual Basic 2008
Slide 1- 37
FOURTH EDITION
Tony GaddisHaywood Community College
Kip IrvineFlorida International University
Slide 1- 37
COPYRIGHT 2007: Dr. David Scanlan, CSUS
This OOP stuff is easy once you get some practice.
A GENTLE INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP)TERMS AND CONCEPTS.
Slide 1- 38
COPYRIGHT 2007: Dr. David Scanlan, CSUS
OBJECTIVES• To gain a very basic understanding of Object Oriented Programming (OOP)
terms and concepts using examples from everyday life.
These are the main OOP terms that we will cover:• CLASS (CODE that is COPIED in order to create an object)
• PROPERTIES ( also called ATTRIBUTES)• BEHAVIORS (also called METHODS)• OBJECT (The copied code from a class)• INSTANTIATION (The process of CREATING an object)• INSTANCE (An OBJECT created from a class)• INHERITANCE (Covered later in the course)• POLYMORPHISM (Covered later in the course) • ENCAPSULATION (Covered later in the course)
• These OOP terms and concepts will be learned using everyday items like washing machines, caster wheels, and nerds. Actual OO computer programming will delayed until you get a good understanding of its terms and concepts. Slide 1- 39
COPYRIGHT 2007: Dr. David Scanlan, CSUS
The Nerd CLASS CLASS = TEMPLATE = BLUEPRINT = MODEL
A CLASS is easy to understand if you think of it asa TEMPLATE, a BLUEPRINT, or a MODEL.
In my opinion, the word CLASS, was a poor choice forthis concept: Template or blueprint would have been a better choice.
Slide 1- 40
COPYRIGHT 2007: Dr. David Scanlan, CSUS
NERD CLASSCLASS• This is a CLASS (or template) called NERD.• This object has PROPERTIES and
BEHAVIORS.
Nerd CLASS name
PROPERITES
BEHAVIORS or METHODS
SmartThinSocial clodHair color etc...Read bookTurn on computerType on keyboardChew pizza Put pencil in pocket protectoretc...
The Nerd CLASSCLASS = TEMPLATE = BLUEPRINT = MODEL
Think of this as template for making more nerds.
Slide 1- 41
COPYRIGHT 2007: Dr. David Scanlan, CSUS
1.6 Concepts In OOP: Object
• Using the template, we can create as many new OBJECTS as we want.
OBJECT• If we select one of these items in
the CLASS as a template for creating another, we call the new one an OBJECT.
Let’s choose this model as a template from which to create new nerds.
NERD CLASS
The Nerd CLASSCLASS = TEMPLATE = BLUEPRINT = MODEL
Think of this as template for making more nerds.
Slide 1- 42
COPYRIGHT 2007: Dr. David Scanlan, CSUS
OOP
for
Nerds
VB.NET
“I was INSTANTIATED by accident. Yes, I admit it, I am an OBJECT from
the nerd CLASS.
You can even call me an INSTANCE from the nerd
CLASS.
Slide 1- 43
COPYRIGHT 2007: Dr. David Scanlan, CSUS
The Nerd CLASS CLASS = TEMPLATE = BLUEPRINT = MODEL
A CLASS is easy to understand if you think of it asa TEMPLATE, a BLUEPRINT, or a MODEL.
In my opinion, the word CLASS, was a poor choice forthis concept: Template or blueprint would have been a better choice.
Slide 1- 44
COPYRIGHT 2007: Dr. David Scanlan, CSUS
What is a class in Visual Basic?
A Class is simply previously written code with1. Properties2. Methods (also called Behaviors)An Object is a copy of the Class code with the same1. Properties2. MethodsNOTE: WE CAN MAKE AS MANY COPIES (OBJECTS) OF A CLASS AS WE WANT.
Example: The items in the Toolbox such as Button, Labels, Textboxes, etc. are classes.
When we click on a class, we put a copy of the class's code onto the Form.
Instructor: Give demo. Use Toolbox and create OBJECTS from CLASSES.
CLASSES OBJECTS
Slide 1- 45
Chapter
Introduction to Programming and Visual Basic 2008
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1
Slide 1- 46
Computer Systems:
Hardware and Software
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1.1DR SCANLAN: SKIP PART 1.1AND JUMP
DIRECTLY TO PART 1.2
IT IS ASSUMED THAT STUDENTS
KNOW PART 1.1 FROM 1A, 1B, AND 1CSlide 1- 47
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Refers to the physical components Not one device but a system of many devices Major types of components include:
Central Processing Unit Main memory Secondary storage devices Input devices Output devices
Computer Hardware
Slide 1- 48
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Organization of a Computer System
Slide 1- 49
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Fetches instructions from main memory Carries out the operations commanded by the
instructions Each instruction produces some outcome CPU gets instructions from a program A program is an entire sequence of instructions Instructions are stored as binary numbers Binary number - a sequence of 1’s and 0’s
The CPU
Slide 1- 50
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Commonly known as random access memory, or just RAM
Holds instructions and data needed for programs that are currently running
RAM is usually a volatile type of memory Contents are lost when power is turned off
Used as temporary storage
Main Memory
Slide 1- 51
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
A nonvolatile storage medium Contents retained while power is off
Hard disk drives are most common Records data magnetically on a circular disk Provides fast access to large amounts of data
Optical devices store data on CD’s as pits USB flash memory devices
High capacity device plugs into USB port Portable, reliable, and fits easily in a pocket
Secondary Storage
Slide 1- 52
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Any type of device that provides data to a computer from the outside world
For example: Keyboard Mouse Scanner
Input Devices
Slide 1- 53
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Any type of device that provides data from a computer to the outside world
Examples of output data: A printed report An image such as a picture A sound
Common output devices include: Monitor (display screen) Printer
Output Devices
Slide 1- 54
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
The programs that run on a computer Two major categories
Operating systems Controls the processes within the computer Manages the computer's hardware devices
Application Software Solve problems or perform tasks needed by users Examples include word processing, spreadsheets,
games, Internet browsers, playing music, etc) Each program is referred to as an application This book develops applications in Visual Basic
Software
Slide 1- 55
Programs and Programming Languages
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1.2
A Program Is a Set of Instructions a Computer Follows in Order to Perform a Task
A Programming Language Is a Special Language Used to Write Computer Programs
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Computers only follow instructions. A computer program is a set of instructions to
the computer. For example, a program to compute gross pay.
We must program the steps. Steps>> Next slide
What Is a Program?
Slide 1- 57
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1. Display message: “Hours worked?"2. User enters hours3. Put hours in memory4. Display message: “Pay Rate?"5. User enters pay rate6. Store pay rate in memory7. GrossPay = Hours * Rage 8. Display Gross Pay
Algorithm = steps for solving a problem.Example: a recipe for baking a cake
Computing Gross Pay
Slide 1- 58
STEPS:
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Wage Calculator
Slide 1- 59
btnCalcGrossPay btnClose
txtHoursWorked
txtPayRate
lblGrossPay
Label1
Label2
Label3
The label controls use the default names (Label1, Textbox1, Button1, Form1, etc.)
Text boxes, buttons, and the Gross Pay label play an active role in the program and have been changed
Dr. Scanlan: Program this with the class following.18 point text for the code.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Memory snapshots show states of the program
3. Store hours worked in memory
6. Store hourly pay rate in memory
7. Multiply hours worked by pay rate and store amount earned in memory
States and Transitions
Slide 1- 60
Program Starting State
hours worked
hourly pay rate
amount earned
??
??
??
Snapshot after Step 3
hours worked
hourly pay rate
amount earned
20
??
??
Snapshot after Step 6
hours worked
hourly pay rate
amount earned
20
25
??
Snapshot after Step 7
hours worked
hourly pay rate
amount earned
20
25
500
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
What the computer understands: Binary Numbers 1001 0111 0111 0110
The CPU processes instructions as a series of 1’s and 0’s called machine language
Programming languages allow us to use words instead of a series of 1’s and 0’s
Compilers (software) translate VB statements into
machine language, so the computer can understand the VB statements (code).
Programming Languages
Slide 1- 61
~0 volts
~5 volts
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Common Programming Languages
Visual Basic Python Javascript Java
C# C C++ PHP
Slide 1- 62
Visual Basic is a: programming language programming environment with tools to:
Create objects on forms, etc. Write programming language statements
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Visual Basic is event-driven An event is an action that takes place within a
program. Clicking a button (a Click event).
Visual Basic controls (buttons, textboxes, etc.) are capable of detecting many, many events.
A program can respond to an event if the programmer writes an event procedure. See Next Slide>>
Event Driven Programming: Events
Slide 1- 63
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Event Driven Programming: Events
Slide 1- 64
When announced, this program will be written in the lab with no notes. You must practice writing this program.
Steps:1. Create Form1 VERY similar to the one shown.2. Set FORM1’s text property to: Wage Calculator3. Set these three labels’ text properties to their
indicated values.Set the name property of the fourth label with
$150.00 to: lblDisplayGrossPay 4. Place the two buttons on Form1
- Set text property of one button to: Calculate Gross Pay- Set text property of the second button to:
Close- Set the Name Property of button Calculate
Gross Pay to: btnCalculateGrossPay5. Double click on the CalculateGrossPay button.
You should see the following:Public Class Form1 Private Sub btnCalculateGrossPay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculateGrossPay.Click
End SubEnd Class
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Event Driven Programming: Events
Slide 1- 65
When announced, this program will be written in the lab with no notes. You must practice writing this program.
Steps:6. Double click on the Close button.
You should see the following:
Public Class Form1
Private Sub btnCalculateGrossPay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculateGrossPay.Click
End Sub
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
End Sub
End Class
7. You have just created two click events, but you now need to place code into these two events.
Place code here
Place code here
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Event Driven Programming: Events
Slide 1- 66
When announced, this program will be written in the lab with no notes. You must practice writing this program.
Steps:8. Finish the program using the code below:9. Run the program.10. Check to be sure the results are correct.
Public Class Form1 Private Sub btnCalculateGrossPay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculateGrossPay.Click lblDisplayGrossPay.Text = FormatCurrency(CDec(txtHourlyRate.Text) * CDec(txtHoursWorked.Text)) End Sub
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click Me.Close() End SubEnd Class
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Event Driven Programming: Events
Slide 1- 67
Event Procedure triggered by aClick Event
-- Pressing the Calculate Gross Pay button triggers a click event procedure which is code that must be written by the programmer.
-- This click event procedure called btnCalculateGrossPay will cause the code below to be executed.
When the button is CLICKED, this Event Procedure (code) is executed.
Event Procedure
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Event Driven Programming: Events
Slide 1- 68
Event Procedure triggered by aClick Event
-- Pressing the Close button triggers a click event procedure which is code that must be written by the programmer.
-- This click event procedure called btnClose will cause the code below to be executed.
When the button is CLICKED, this Event Procedure (code) is executed.
Event Procedure
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Procedural Programming Step by step instructions. Similar to a step-by-step recipe for baking a
cake. Object-Oriented Programming
The step-by-step instruction have already been written for us so that we can easily reuse the code.
Examples: Buttons, Labels, Textboxes, etc… The code to produce these objects has already
been written. Instructor: Create objects from the Toolbox
Methods of Programming
Slide 1- 69
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Procedural programming BUTTON – We would need to write hundreds
of lines of code to create a Button on a Form. This is like writing a procedure for creating a
chocolate cake. Object-Oriented programming
BUTTON – In OOP the code is already written. All we need to do is use a copy of that code.
Example: Double click on a Button in the Tool box and a Button is created on the Form.
Methods of Programming
Slide 1- 70
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Examples of Objects
Slide 1- 71
FormTextboxes
Labels
Buttons
ButtonsLabelThe form is the larger rectangular object onwhich other objects areplaced.
Review on Objects
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Examples of Objects GUI: Graphical User Interface Objects consist of:
Properties Properties on this form:
Text Color Size Position Etc.
Methods Calculate Gross Pay Close Min, Max Etc.
Slide 1- 72
Review on Objects
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Examples of Objects
Form elements are objects called controls
This form has: Two TextBox controls Four Label controls Two Button controls
The value displayed by a control is held in the text property of the control
Left button text property is Calculate Gross Pay Buttons have methods attached to click events
Slide 1- 73
Review on Objects
More About Controls and Programming
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1.3
As a Visual Basic Programmer, You Must Design and Create the Two Major Components of an Application: the GUI Elements (Forms and Other Controls) and the
Programming Statements That Respond to And/or Perform Actions (Event Procedures)
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
As a Windows user you’re already familiar with many Visual Basic controls:
Label - displays text the user cannot change TextBox - allows the user to enter text
- also allows the user to display text Button – performs an action when clicked RadioButton - A round button that is selected or
deselected with a mouse click CheckBox – A box that is checked or unchecked with a
mouse click Horizontal and Vertical Scroll Bars Form - A window that contains these controls
Tutorial 1-3 demonstrates these controls
Visual Basic Controls
Slide 1- 75
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Tutorial 1-3, Visual Basic Controls
Slide 1- 76
You must run this program and play with it.See Tutorial 1-3 in the book for directions.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
All controls have properties Properties have a value (values) The Name Property allows the programmer to
access a control from within a program.
Name Property
Slide 1- 77
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Examples of Names
Slide 1- 78
btnCalcGrossPay btnClose
txtHoursWorked
txtPayRate
lblGrossPay
Label1
Label2
Label3
The label controls use the default names (Label1, Textbox1, Button1, Form1, etc.)
Text boxes, buttons, and the Gross Pay label play an active role in the program and have been changed
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Control names must start with a letter Remaining characters may be letters, digits, or underscore 1st 3 lowercase letters indicate the type of control
txt… for Text Boxes lbl… for Labels btn… for Buttons
After that, capitalize the first letter of each word txtHoursWorked is clearer than txthoursworked NO spaces: txtHours Worked (Error)
Naming Conventions
Slide 1- 79
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Event Handler – Compute Gross Pay
Slide 1- 80
Private Sub btnCalcGrossPay_Click(ByVal sender As System.Object, _ByVal e As System.EventArgs) Handles btnCalcGrossPay.Click
'Define a variable to hold the gross pay.Dim decGrossPay As Decimal
'Convert the values in the text boxes to decimal numbers,'and calculate the gross pay.decGrossPay = CDec(txtHoursWorked.Text) * CDec(txtPayRate.Text)
'Format the gross pay for currency display and'assign it to the Text property of a label.lblGrossPay.Text = FormatCurrency(decGrossPay)
End Sub
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Event Handler - Close
Slide 1- 81
Private Sub btnClose_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnClose.Click
'End the program by closing its window.
Me.Close()
End Sub
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Keywords: Words with special meaning to Visual Basic (e.g., Private, Sub)
Programmer-defined-names: Names created by the programmer (e.g., decGrossPay, btnClose)
Operators: Special symbols to perform common operations (e.g., +, -, *, and /)
Remarks: Comments inserted by the programmer – these are ignored when the program runs (e.g., any text preceded by a single quote) ‘This is a comment. Note the apostrophe (single quote).
Language Elements
Slide 1- 82
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Syntax defines the correct use of key words, operators, & programmer-defined names
Similar to the syntax (rules) of English that defines correct use of nouns, verbs, etc.
A program that violates the rules of syntax will not run until corrected
Language Elements: Syntax
Slide 1- 83
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
EXAMPLE OF AN "IN-CLASS LAB"
Slide 1- 84
btnCalcGrossPay btnClose
txtHoursWorked
txtPayRate
lblGrossPay
Label1
Label2
Label3
Points 0 or 5
Be sure to fill out the AS15 Form as shown on the next slide and have it ready for instructor
to collect. The form will not be collected if you have not completed the lab correctly.
You will be given 30 minutes to complete the Lab.
Steps:
1. This program must be done totally from memory. Immediate failure of the course will result if this rule is not followed. Remove all disks and flash drives from the system.
2. Create a GUI as seen below.
3. Use the object names as given below.
4. Code the program so that it produces the correct result.
5. Raise your hand as soon as you are finished so that instructor can grade you.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
How to fill out the 15AS FORM
ID FIELD- Use the RFID card ID number that is on your attendance card. Example: 12345- TWO POINTS OFF IF NOT DONE CORRECTLY.
Left justify your ID number as seen.
Place the following
answers on your
Scantron:
1. a
2. a
3. a
4. a
5. a
Last NameFirst NameLab #DateHour
Slide 1- 85
The Programming Process
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1.4
The Programming Process Consists of Several Steps, Which Include Design, Creation, Testing, and
Debugging Activities
Slide 1- 86
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Clearly define what the program is to do For example, the Wage Calculator program:
Purpose: To calculate the user’s gross pay Input: Number of hours worked, hourly pay rate Process: Multiply number of hours worked by hourly
pay rate (result is the user’s gross pay) Output: Display a message indicating the user’s gross
pay
Step 1 of Developing an Application
Slide 1- 87
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Visualize the application running on the computer and design its user interface
Step 2 of Developing an Application
Slide 1- 88
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Make a list of the controls needed
Step 3 of Developing an Application
Slide 1- 89
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
Label (default) Description for Number of Hours Worked TextBoxLabel (default) Description for Hourly Pay Rate TextBoxLabel (default) Description for Gross Pay Earned LabelForm (default) A form to hold these controls
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Define values for each control's relevant properties:
Step 4 of Developing an Application
Slide 1- 90
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 "" (Called a null string)TextBox txtPayRate "" (Called a null string)
Button btnCalcGrossPay "Calculate Gross Pay"Button btnClose "Close"
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
List the methods needed for each control:
Step 5 of Developing an Application
Slide 1- 91
Method DescriptionbtnCalcGrossPay_Click Multiplies hours worked by hourly pay rate
These values are entered into the txtHoursWorked and txtPayRate TextBoxes
Result is stored in lblGrossPay Text property
btnClose_Click Terminates the application
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Create pseudocode or a flowchart of each method: Pseudocode is an English-like description in
programming language terms
A flowchart is a diagram that uses boxes and other symbols to represent each step
Step 6 of Developing an Application
Slide 1- 92
TWO EXAMPLES OF PSEUDOCODE:Store Hours Worked x Hourly Pay Rate in decGrossPay.Store the value of decGrossPay in lblGrossPay.Text.
Start End
Multiply hours worked by
hourly payrate. Store result in decGrossPay.
Copy value in decGrossPay
to lblGrossPay text property
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Check the code for errors: Closely examine flowchart and/or pseudocode Step through each operation as though you are the
computer. Play being the computer. Use a piece of paper to jot down the values of
variables and properties as they change. Verify that the expected results are achieved
Step 7 of Developing an Application
Slide 1- 93
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Use Visual Basic to create the forms and other controls identified in step 3 This is the first use of Visual Basic, all of the
previous steps have just been on paper Develop what the user will see on the form.
Step 8 of Developing an Application
Slide 1- 94
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Use Visual Basic to write the code for the event procedures and other methods created in step 6 This is the second step on the computer In this step you develop the methods behind the
click event for each button Unlike the form developed on step 8, this portion of
the application is invisible to the user
Step 9 of Developing an Application
Slide 1- 95
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Attempt to run the application - find syntax errors Correct any syntax errors found Syntax errors are the incorrect use of an element
of the programming language Repeat this step as many times as needed All syntax errors must be removed before Visual
Basic will create a program that actually runs
Step 10 of Developing an Application
Slide 1- 96
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Run the application using test data as input Run the program with a variety of test data Check the results to be sure that they are correct Incorrect results are referred to as a runtime error Correct any runtime errors found Repeat this step as many times as necessary
Step 11 of Developing an Application
Slide 1- 97
Visual Studio and theVisual Basic Environment
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
1.5
Visual Studio Consists of Tools That You Use to Build Visual Basic
Applications
Slide 1- 98
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Visual Studio is an integrated development environment, often abbreviated as IDE
Provides everything needed to create, test, and debug software including: The VB language Form design tools to create the user interface Debugging tools to help find and correct
programming errors Visual Studio supports other languages beside
Visual Basic such as C++ and C#
The Visual Studio IDE
Slide 1- 99
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Tutorial 1-4 introduces elements of the IDE: Customizing the IDE Design window – a place to design and create a form Solution Explorer window – shows all the files in the
solution Properties window – modify properties of an object Dynamic Help window – a handy reference tool Toolbar – contains icons for frequently used functions Toolbox window – Classes used in form design Tooltips – a short description of button’s purpose
The Visual Basic Environment
Slide 1- 100
THE END
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
THREE TYPE OF ERRORS IN PROGRAMMING
Slide 1- 101
1. Syntax errors 2. Runtime errors 3. Logic errors Generally speaking, the errors become more difficult to find and fix as you move down the above list.
Syntax errors--In effect, syntax errors represent grammar errors in the use of the programming language. Common examples are:--Misspelled variable and function names --Missing semicolons --Improperly matches parentheses, square brackets, and curly braces --Incorrect format in selection and loop statements
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
THREE TYPE OF ERRORS IN PROGRAMMING
Slide 1- 102
Runtime errorsRuntime errors occur when a program with no syntax errors asks the computer to do something that the computer is unable to reliably do. Common examples are:--Trying to divide by a variable that contains a value of zero --Trying to open a file that doesn't exist --There is no way for the compiler to know about these kinds of errors when the program is compiled.
Logic errorsLogic errors occur when there is a design flaw in your program. Common examples are:--Multiplying when you should be dividing --Adding when you should be subtracting --Opening and using data from the wrong file --Displaying the wrong message