Programming with Microsoft Visual Basic 2012 Chapter 2: Designing Applications.

Slides:



Advertisements
Similar presentations
Chapter 1: An Introduction to Visual Basic 2012
Advertisements

Programming with Microsoft Visual Basic th Edition
Chapter 2: Designing Applications
Chapter 2: Designing Applications
Creating an OOED Application
Programming with Microsoft Visual Basic 2008 Fourth Edition
Tutorial 2: Designing Applications1 Tutorial 2 Designing Applications.
PROGRAMMING WITH MICROSOFT VISUAL BASIC TH EDITION Chapter Two Designing Applications.
Microsoft Excel 2003 Illustrated Complete A Worksheet Formatting.
1.
1.
IMS1906 Programming in VB.NET Week 3 – Lecture 1 Application Development © Angela Carbone Monash University School of Information Management.
Tutorial 21 Procedure-Oriented vs Object- Oriented/Event-Driven w Procedure-oriented Emphasis of a program is on how to accomplish a task User has little,
Microsoft Visual Basic 2010: Reloaded Fourth Edition
COMPREHENSIVE Excel Tutorial 8 Developing an Excel Application.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter One An Introduction to Visual Basic 2010.
Slide 1 Chapter 2 Visual Basic Interface. Slide 2 Chapter 2 Windows GUI  A GUI is a graphical user interface.  The interface is what appears on the.
Chapter 8: String Manipulation
Variables, Constants, Methods, and Calculations Chapter 3 - Review.
Visual Basic Chapter 1 Mr. Wangler.
Chapter 3: Using Variables and Constants
Chapter Four The Selection Structure
Programming with Microsoft Visual Basic th Edition Chapter Two Designing Applications.
Programming with Microsoft Visual Basic 2012 Chapter 12: Web Applications.
Chapter 4: The Selection Structure
Key Applications Module Lesson 16 — Excel Essentials Computer Literacy BASICS.
1 Microsoft Visual Basic 2010 Week Two Designing Applications.
Chapter 1 P. 1 Writing Windows applications with Visual Basic Figure 1.1 The first program works as follows: (These operations can be performed in any.
Microsoft Office Illustrated Introductory, Premium Edition A Worksheet Formatting.
© 2006 Lawrenceville Press Slide 1 Chapter 3 Visual Basic Interface.
Microsoft Visual Basic 2005 BASICS Lesson 4 Mathematical Operators.
Clearly Visual Basic: Programming with Visual Basic 2008
Chapter 12: How Long Can This Go On?
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 2 Creating a User Interface.
Input, Output, and Processing
 Application – another name for a program.  Interface – is what appears on the screen when the application is running.  Program Code – is instructions.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Microsoft Visual Basic 2012 CHAPTER THREE Program Design and Coding.
Microsoft Visual Basic 2010 CHAPTER THREE Program Design and Coding.
Microsoft Visual Basic 2005 CHAPTER 4 Variables and Arithmetic Operations.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Chapter Two Designing Applications Programming with Microsoft Visual Basic th Edition.
Introduction to Programming with RAPTOR
Chapter Two Designing Applications Programming with Microsoft Visual Basic th Edition.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Three Memory Locations and Calculations.
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Spreadsheets What is Excel?. Objectives 1. Identify the parts of the Excel Screen 2. Identify the functions of a spreadsheet 3. Identify how spreadsheets.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter One An Introduction to Visual Basic 2008.
Chapter 3 I Need a Tour Guide (Introduction to Visual Basic 2010) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Addison Wesley is an imprint of © 2011 Pearson Addison-Wesley. All rights reserved. Chapter 2 Creating Applications with Visual Basic.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
Visual Basic.NET Programming for the Rest of Us Keith Mulbery Utah Valley State College.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
Microsoft Visual Basic 2012: Reloaded Fifth Edition Chapter One An Introduction to Visual Basic 2012.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
Programming with Microsoft Visual Basic 2012 Chapter 3: Using Variables and Constants.
Chapter 4: Do-It-Yourself Designing (Designing Interfaces)
Excel Tutorial 8 Developing an Excel Application
Visual Basic.NET Windows Programming
Microsoft Visual Basic 2005: Reloaded Second Edition
Chapter 1: An Introduction to Visual Basic 2015
CIS16 Application Programming with Visual Basic
Chapter 4: The Selection Structure
CIS16 Application Programming with Visual Basic
Variables and Arithmetic Operations
Tutorial 2 Designing Applications
Introduction to Programming
Presentation transcript:

Programming with Microsoft Visual Basic 2012 Chapter 2: Designing Applications

Previewing the Play It Again Movies Application Play It Again Movies application –Allows salespeople to enter the date and number of DVDs and Blu-rays sold –Calculates and displays the total number of discs ordered and the total sales for the order Programming with Microsoft Visual Basic Figure 2-3 Print preview window Figure 2-2 Completed sales receipt

Lesson A Objectives After studying Lesson A, you should be able to: Plan an object-oriented Windows application in Visual Basic 2012 Complete a TOE (Task, Object, Event) chart Follow the Windows standards regarding the layout and labeling of controls Programming with Microsoft Visual Basic 20123

Developing an application is like building a home The role of the programmer is analogous to that of a builder Bugs are problems that affect application functions Programming with Microsoft Visual Basic Creating an Object-Oriented Application

Programming with Microsoft Visual Basic Figure 2-4 Processes used by a builder and a programmer Creating an Object-Oriented Application (cont.)

Actively involve the user in the planning phase –The end product should closely match the user’s needs and wants TOE chart –Used to record tasks, objects, and events required for the application Programming with Microsoft Visual Basic Planning an Object-Oriented Application Figure 2-5 Steps for planning an OO application

Programming with Microsoft Visual Basic Identifying the Application’s Tasks What information will the application need to display on the screen and/or print on the printer? What information is entered into the user interface? What information will the application need to calculate to produce the desired result? How will the user end the application? Will previous information need to be cleared from the screen before new information is entered? Figure 2-6 Sample of the store’s current sales receipt Planning an Object-Oriented Application (cont.)

Programming with Microsoft Visual Basic Figure 2-7 Tasks entered in a TOE chart Planning an Object-Oriented Application (cont.)

Identifying the Objects Assign each task to an object in the user interface Objects used here: –Label control Displays information that the user should not change –Button control Performs an action immediately after a Click event –Text box Provides an area for the user to enter data Programming with Microsoft Visual Basic Planning an Object-Oriented Application (cont.)

Programming with Microsoft Visual Basic Figure 2-8 Tasks and objects entered in a TOE chart Planning an Object-Oriented Application (cont.)

Programming with Microsoft Visual Basic Identifying the Events Determine which event (if any) must occur for an object to carry out its assigned task Text boxes and label controls –No special event is needed btnCalc, btnClear, and btnExit buttons –Perform assigned tasks when clicked Planning an Object-Oriented Application (cont.)

Programming with Microsoft Visual Basic Figure 2-9 Completed TOE chart ordered by task Figure 2-10 Completed TOE chart ordered by object Planning an Object-Oriented Application (cont.)

Programming with Microsoft Visual Basic Drawing a Sketch of the User Interface Follow Windows standards for designing the interface In Western countries, information flows either vertically or horizontally –Vertical arrangement: Information flows from top to bottom, with essential information located in the first column –Horizontal arrangement: Information flows from left to right, with essential information placed in the first row Planning an Object-Oriented Application (cont.)

Programming with Microsoft Visual Basic Figure 2-11 Vertical arrangement of the Play It Again Movies application Figure 2-12 Horizontal arrangement of the Play It Again Movies application Planning an Object-Oriented Application (cont.)

Programming with Microsoft Visual Basic White space or containers may be used to group related controls Containers –Objects used to group related controls –Examples: GroupBox, Panel, TableLayoutPanel Label controls that display output should have meaningful names –Example: “Total Sales” identifies the lblTotalSales label Identifying labels should end with a colon (:) –Example: “Total Sales:” Planning an Object-Oriented Application (cont.)

Programming with Microsoft Visual Basic Sentence capitalization –Only the first letter in the first word is capitalized –Use for identifying labels Book title capitalization –Capitalize the first letter of each word except articles, conjunctions, and prepositions –Use for button text Buttons should be aligned –Also same height and width Group related controls close to each other Planning an Object-Oriented Application (cont.)

Programming with Microsoft Visual Basic Planning an Object-Oriented Application (cont.)

Programming with Microsoft Visual Basic Lesson A Summary Steps to create an OO application: –Meet with the client –Plan the application Identify needed tasks, objects, and events Identify information needed as input to produce the desired result –Build the user interface –Code the application –Test and debug the application –Assemble the documentation

Lesson B Objectives After studying Lesson B, you should be able to: Build the user interface using your TOE chart and sketch Follow the Windows standards regarding the use of graphics, fonts, and color Set a control’s BorderStyle, AutoSize, and TextAlign properties Add a text box to a form Lock the controls on the form Assign access keys to controls Set the TabIndex property Programming with Microsoft Visual Basic

Programming with Microsoft Visual Basic Building the User Interface Use the TOE chart and sketch as guides when building the user interface –Place appropriate controls on forms –Set applicable properties of controls Features of the UI used in this lesson’s application: –Information is arranged vertically –Controls are aligned and appropriately labeled Try to create an interface that no one notices

Building the User Interface (cont.) Programming with Microsoft Visual Basic Figure 2-13 Partially completed interface for the Play It Again Movies application

Programming with Microsoft Visual Basic Building the User Interface (cont.) Including Graphics in the User Interface Graphics –Icons or pictures added to an interface –Used to emphasize or clarify a portion of the screen, or for aesthetic purposes The human eye is attracted to pictures before text –Include graphics sparingly –Graphics for aesthetic use should be small and positioned to avoid distracting the user

Programming with Microsoft Visual Basic Building the User Interface (cont.) Selecting Fonts for the Interface GUI DESIGN TIP: Selecting Font Types, Styles, and Sizes –Use only one font type—typically Segoe UI (pronounced “see-go”)—for all of the text in the interface –Use no more than two different font sizes in the interface –Avoid using italics and underlining because both font styles make text difficult to read –Limit the use of bold text to titles, headings, and key items that you want to emphasize

Programming with Microsoft Visual Basic Building the User Interface (cont.) Adding Color to the Interface Build the interface using black, white, and gray; only add color if you have a good reason to do so Use white, off-white, or light gray for the background; use black for the text Never use a dark color for the background or a light color for the text; a dark background is hard on the eyes, and light- colored text can appear blurry Limit the number of colors in an interface to three, not including white, black, and gray; the colors you choose should complement each other Never use color as the only means of identifying an element in the interface

Programming with Microsoft Visual Basic Building the User Interface (cont.) The BorderStyle, AutoSize, and TextAlign Properties The BorderStyle property can be set to None, FixedSingle, or Fixed3D –None is used for labels –FixedSingle surrounds the control with a thin line Used for labels that display program output –Fixed3D gives the control a three-dimensional appearance Used for text boxes The AutoSize property determines if a control automatically sizes to fit its current contents –Typically set to false for label controls that display program output The TextAlign property can be set to nine different values

Programming with Microsoft Visual Basic Building the User Interface (cont.) Adding a Text Box Control to the Form A text box control provides an area for data entry Use the TextBox tool to add a text box control –Make all text boxes the same size and align them using snap lines –Blue snap lines are used for vertical alignment –Pink snap lines are used for horizontal alignment Figure 2-14 Snap lines shown in the interface

Programming with Microsoft Visual Basic Locking the Controls on a Form Lock controls after they are properly placed to avoid inadvertently moving them A locked control is identified by a small lock To lock controls: –Right-click the form (or any control on the form) –Click Lock Controls on the FORMAT menu Follow the same procedure to unlock controls

Programming with Microsoft Visual Basic Assigning Access Keys Access key –Enables an object to be selected using the keyboard –Key combination: Alt key + letter or number Each access key must be unique Shown in the interface as an underlined letter To assign an access key, include an ampersand (&) in the control’s caption –Example: “&Calculate Order” assigns ‘C’ to the button

Programming with Microsoft Visual Basic Assigning Access Keys (cont. ) Reasons to assign access keys: –Allow the user to work even if the mouse does not –Allow fast typists to keep their hands on the keyboard –Allow people with disabilities that prevent them from using a mouse to be able to use an application Follow Windows standards for assigning commonly used access keys

Programming with Microsoft Visual Basic Controlling the Tab Order Focus –The state in which a control is ready to accept user input or action –Pressing the Tab key or access key shifts the focus TabIndex property –A number representing the order in which a control will receive the focus when the user presses the Tab key –A control with a TabIndex of 0 receives the focus first Set TabIndex using the Properties window or the Tab Order option on the VIEW menu –Make a list of objects to determine the proper order

Programming with Microsoft Visual Basic Controlling the Tab Order (cont.) Figure 2-15 List of controls and TabIndex values Figure 2-16 TabIndex boxes showing the correct TabIndex values

Programming with Microsoft Visual Basic Lesson B Summary Use appropriate graphics, fonts, and colors in an interface Set the BorderStyle, AutoSize, and TextAlign properties To lock/unlock controls on a form, use the Lock Controls option on the FORMAT menu To assign an access key to a control, type an ampersand (&) in the Text property of the control or identifying label To set the tab order, set the TabIndex property to a number that represents the order in which you want the control to receive the focus

Lesson C Objectives After studying Lesson C, you should be able to: Code an application using its TOE chart Plan an object’s code using either pseudocode or a flowchart Write an assignment statement Send the focus to a control during run time Include internal documentation in the code Write arithmetic expressions Use the Val and Format functions Print an interface from code Locate and correct syntax errors Programming with Microsoft Visual Basic

Coding the Application Code –Instructions added to an application Coding is done after planning and building the interface TOE charts show which objects and events need to be coded Play It Again Movies application code requirements: –Four buttons associated with Click events Programming with Microsoft Visual Basic

Coding the Application (cont.) Programming with Microsoft Visual Basic Figure 2-22 TOE chart (ordered by object) for Play It Again Movies Figure 2-21 Play It Again Movies user interface from Lesson B

Coding the Application (cont.) Using Pseudocode to Plan a Procedure Pseudocode –Short phrases used to describe the steps a procedure must take to accomplish its goal –Travel directions are a type of pseudocode btnCalc Click event procedure –Calculates the total number of phones ordered and the total price –Displays the results at run time Programming with Microsoft Visual Basic

Coding the Application (cont.) Programming with Microsoft Visual Basic Figure 2-23 Pseudocode for the Play It Again Movies application

Coding the Application (cont.) Using a Flowchart to Plan a Procedure A flowchart shows program logic using standardized symbols –Oval: Start/stop symbol –Rectangle: Process symbol; represents a task –Parallelogram: Input/output symbol –Flowlines connect the symbols Flowcharts depict the same logic as pseudocode Programming with Microsoft Visual Basic

Coding the Application (cont.) Programming with Microsoft Visual Basic Figure 2-24 Flowcharts for Play It Again Movies

Coding the btnClear Control’s Click Event Procedure btnClear control’s task –Clear the screen for the next order String –Zero or more characters enclosed in quotation marks ("") Zero-length string (or empty string) –A pair of quotation marks with nothing between them ("") Two ways to remove the control contents at run time: –Assign a zero-length string to the control’s Text property –Assign String.Empty to the control’s Text property Programming with Microsoft Visual Basic

Assigning a Value to a Property During Run Time Assignment statement –An instruction assigning a value to an object at run time Syntax: object.property = expression –object and property are the object and property names –expression contains the value to be assigned Assignment operator (=) –Assigns the value on the right side to the object on the left side Programming with Microsoft Visual Basic Figure 2-27 First assignment statement entered in the procedure Coding the btnClear Control’s Click Event Procedure (cont.)

Using the Focus Method Allows you to move the focus to a specified control during run time Syntax: object.Focus() –object is the name of the control that receives the focus Programming with Microsoft Visual Basic Coding the btnClear Control’s Click Event Procedure (cont.)

Internally Documenting the Program Code Comments –Internal documentation in a program –Used by programmers to document a procedure’s purpose or explain sections of code –Help make code readable To create a comment, place an apostrophe (’) before a statement –The computer ignores all characters after the apostrophe for the rest of the line Comments are color-coded in the IDE Programming with Microsoft Visual Basic Coding the btnClear Control’s Click Event Procedure (cont.)

Programming with Microsoft Visual Basic Figure 2-28 btnClear control’s Click event procedure Figure 2-29 Comments entered in the General Declarations section Coding the btnClear Control’s Click Event Procedure (cont.)

Coding the btnPrint Control’s Click Event Procedure Programming with Microsoft Visual Basic Figure 2-30 Syntax and examples of printing the interface from code

Programming with Microsoft Visual Basic Figure 2-33 Completed Click event procedure for the btnPrint control Figure 2-32 Print preview window Coding the btnPrint Control’s Click Event Procedure (cont.)

Writing Arithmetic Expressions Order of operations: –PEMDAS (Parentheses, Exponents, Multiplication, Division, Addition, Subtraction) Integer division operator –Returns a whole number Modulus operator –Returns the remainder of the division Programming with Microsoft Visual Basic Figure 2-34 Most commonly used arithmetic operators

Writing Arithmetic Expressions (cont.) Programming with Microsoft Visual Basic Figure 2-36 Expressions containing more than one operator having the same precedence

Coding the btnCalc Control’s Click Event Procedure Programming with Microsoft Visual Basic Figure 2-37 Illustration of the total discs sold calculation Figure 2-38 Illustration of the total sales calculation

Programming with Microsoft Visual Basic Figure 2-39 Interface showing the incorrect results of the calculations The Val Function A function is a predefined procedure that performs a task and returns a value Val temporarily converts a string to a number and returns the number Syntax: Val(string) You can use Val to correct calculations in the btnCalc control’s Click event procedure Coding the btnCalc Control’s Click Event Procedure (cont.)

Programming with Microsoft Visual Basic Figure 2-40 Syntax and examples of the Val function Figure 2-41 Val function entered in the assignment statements Coding the btnCalc Control’s Click Event Procedure (cont.)

Programming with Microsoft Visual Basic The Format Function Improves the appearance of numbers Syntax: Format(expression, style) –expression: Specifies the number, date, time, or string to format –style: A predefined or user-defined format style Currency: Example of a format style that displays a number with a dollar sign and two decimal places Coding the btnCalc Control’s Click Event Procedure (cont.)

Programming with Microsoft Visual Basic Figure 2-43 Format function’s syntax and some of the predefined format styles Coding the btnCalc Control’s Click Event Procedure (cont.)

Programming with Microsoft Visual Basic Figure 2-44 Format function entered in the procedure Figure 2-45 Formatted total sales amount shown in the interface Coding the btnCalc Control’s Click Event Procedure (cont.)

Testing and Debugging the Application Programming with Microsoft Visual Basic Test an application using some sample data –Use both valid and invalid data Valid data –Data that the application is expecting Invalid data –Data that the application is not expecting Debugging –The process of locating and correcting errors in a program –Errors can be related to either syntax or logic

Programming with Microsoft Visual Basic Syntax error –Occurs when a rule of a programming language is broken –Typos Logic error –Occurs when the syntax is correct, but the outcome is not what was desired –Causes may include missing instructions, instructions out of order, or the wrong type of instruction Run time error –Occurs when an application is running and the application stops Testing and Debugging the Application (cont.)

Programming with Microsoft Visual Basic Figure 2-46 Suggestion for fixing the error Figure 2-47 Message dialog box Testing and Debugging the Application (cont.)

Programming with Microsoft Visual Basic Figure 2-48 Error List window in the IDE Testing and Debugging the Application (cont.)

Assembling the Documentation Programming with Microsoft Visual Basic Important documentation –Planning tools –Printout of the application’s interface and code Your planning tools include: –TOE chart –Sketch of interface –Flowcharts and/or pseudocode

Assembling the Documentation (cont.) Programming with Microsoft Visual Basic Figure 2-49 Play It Again Movies code

Programming with Microsoft Visual Basic Lesson C Summary Use pseudocode or a flowchart to plan an object’s code To assign a value to the property of an object while an application is running, use an assignment statement with the syntax object.property = expression To create comments, begin the comment text with an apostrophe (’) Use the integer division operator (\) to divide and return an integer result

Programming with Microsoft Visual Basic Lesson C Summary (cont.) Use the modulus operator to divide two numbers and return the remainder Use the PrintForm tool to print the form To temporarily convert a string to a number, use the Val function Use the Format function to improve the appearance of numbers The application should be tested with both valid and invalid data