Brief description on how to navigate within this presentation (ppt)

Slides:



Advertisements
Similar presentations
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Advertisements

Programming In Visual Basic .NET
110-H1 More VB Tools Creating a Menu: What is a menu? a group of (related) commands displayed at at the top of an application Top level menu Disabled command.
Dialog Boxes and Menus. Menus Menu Bar Contains menus which drop down to display list of menu items Each item has a name and text property Each item has.
Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved.
Chapter 6 Multiform Projects Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
Writing General Procedures Often you will encounter programming situations in which multiple procedures perform the same operation This condition can occur.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 06.
Example 2.
C# Programming: From Problem Analysis to Program Design1 Programming Based on Events C# Programming: From Problem Analysis to Program Design 3 rd Edition.
Chapter 5 - Menus, Sub Procedures, and Sub Functions  Menus - controls - properties and events –menu editor - create and change –defining menus - menu.
Using the Visual Basic Editor Visual Basic for Applications 1.
Scope of Variables and Constants A Variable or Constant may exist and be Visible for an entire project, for only one form, or for only one procedure Therefore,
Promoting Code Reuse Often in programming, multiple procedures will perform the same operation IN OTHER WORDS – the same piece of code will do the same.
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Word Project 8 Working with Macros and Visual Basic for Applications (VBA)
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Chapter 8: String Manipulation
Visual Basic Chapter 1 Mr. Wangler.
CIS162AD - C# Methods, Menus, and Dialog Boxes 05_methods_menus.ppt.
05/09/ Introducing Visual Basic Sequence Programming.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. WORD 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 22 Macros.
CHAPTER SIX Reducing Program Complexity General Sub Procedures and Developer-defined Functions.
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
Multiple Forms, Standard Modules, And Menus
CHAPTER SIX Reducing Program Complexity General Sub Procedures and Developer-defined Functions.
5-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures.
Chapter 5 Menus, Common Dialog Boxes, and Methods Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
 Application – another name for a program.  Interface – is what appears on the screen when the application is running.  Program Code – is instructions.
Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved.
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.
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 6 Multiform Projects.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
CHAPTER SIX Reducing Program Complexity General Sub Procedures and Developer-defined Functions.
6-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Creating Menus Menu Bar – behaves like standard Windows menus Can be used in place of or in addition to buttons to execute a procedure Menu items are controls.
Chapter 5 Menus, Sub Procedures and Sub Functions Programming In Visual Basic.NET.
Creating New Forms Projects can appear more professional when using different windows for different types of information. Select Add Windows Form from.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 6 Looping and Multiple Forms.
Chapter 7 Multiple Forms, Modules, and Menus. Section 7.2 MODULES A module contains code—declarations and procedures—that are used by other files in a.
Chapter 8 Multiple Forms, Modules, and Menus. Introduction This chapter demonstrates how to: – Add multiple forms to a project – Create a module to hold.
Dive Into® Visual Basic 2010 Express
Multiple Forms and Menus
Chapter 1: An Introduction to Visual Basic .NET
Excel Tutorial 8 Developing an Excel Application
Visual Basic.NET Windows Programming
Chapter 2: The Visual Studio .NET Development Environment
Apply Procedures to Develop Menus, List Box and Combo Box Objects
Working in the Forms Developer Environment
Chapter 1: An Introduction to Visual Basic 2015
Managing Worksheets And Workbooks
Files.
3.01 Apply Controls Associated With Visual Studio Form
Using Procedures and Exception Handling
Apply Procedures to Develop Menus, List Box and Combo Box Objects
Chapter 2 Visual Basic Interface
Chapter 7 Advanced Form Techniques
Variables and Arithmetic Operations
Multi-form applications and dialogs
Chapter 6 Multiform Projects
MODULE 7 Microsoft Access 2010
Brief description on how to navigate within this presentation (ppt)
Multiple Forms, Modules, and Menus
Object-Oriented Programming: Inheritance and Polymorphism
Presentation transcript:

aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf Brief description on how to navigate within this presentation (ppt) The first time a Key Term from the chapter is used in the ppt it will display in blue Gold colored text boxes display coding examples Slides will be numbered (# of #) when multiple slides on same topic (Slide title) Speaker notes are included where appropriate for slides (*)Denotes either a comment for page reference to textbook or slide reference in ppt

Menus, Common Dialog Boxes, Sub Procedures and Function Procedures 5 Chapter Menus, Common Dialog Boxes, Sub Procedures and Function Procedures McGraw-Hill © 2006 The McGraw-Hill Companies, Inc. All rights reserved.

Objectives Create menus and submenus for program control Display and use the Windows common dialog boxes Create context menus for controls and the form Write reusable code in sub procedures and function procedures and call the procedures from other locations

Menus Menu Bar Contains menus which drop down to display list of menu items Can be used in place of or in addition to buttons to execute a procedure Menu items are controls with properties and events Easy to create menus for a Windows form using the Visual Studio environment’s Menu Designer Menus will look and behave like standard Windows menus Menus are used quite extensively while working with the computer

Defining Menus (1 of 2) MenuStrip component is added to a form MenuStrip is a container to which ToolStripMenu Items, ToolStripComboBoxes, ToolStripSeparators, and ToolStripTextBoxes can be added

Defining Menus (2 of 2) The MenuStrip component appears in the component tray below the form and the Menu Designer allows you to begin typing the text for the menu items. To create the menus simply type where the words "Type Here" appear at the top of the form Each time the text for a new menu is entered a ToolStripMenuItem is automatically added to the MenuStrip’s Items collection

The Text Property Holds the words that appear on the screen – like the Text property of a button or label To conform Windows standards the first menu’s Text property should be File, with a keyboard access key Use the ampersand (&) in the text to specify the key to use for keyboard access Enter and change the Text property for each menu and menu item using the Menu Designer or make the changes in the Text property using the Properties window When typing the words for a menu or menu item the Text property is being entered for the item

The Name Property The File menu item that is added is automatically named FileToolStripMenuItem The items are named so well that there won’t be a need to change the Name property of any menu component If the Text property is changed for any menu item, the item is not automatically renamed; it will need to be renamed Another big improvement to VB 2005 menus is that the Menu Designer is now smart enough to give good names to the menu items

The MenuStrip Items Collection ToolStripMenu Items in the collection can be displayed, reordered, added, deleted using the Items Collection Editor As new menus are created using the Menu Designer, each menu is added to the Items collection that belongs to the MenuStrip

Submenus Filled triangle to the right of the menu item indicates to the user the existence of a submenu Create submenus by moving to the right of a menu item and typing the next item's text The drop-down list of items below a menu name is called a menu When an item on the menu has another list of items that pops up, the new list is calla submenu

Separator Bars Used for grouping menu items according to their purpose Visually represented as a bar across the menu To create a separator bar, add a new menu item and click on its drop-down arrow

Menu Properties Enabled property, True/False-can be set at design or run time Checked property, False/True-can be set at design or run time Used to indicate that an option is selected Setting keyboard shortcuts Select the menu item and In Properties window for menu item, select the ShortcuKeyst property Make choice from drop-down list By default, all new menu items have their Enabled property set to True An enabled menu item appears in black test and is available for selection whereas the grayed out or disabled (key term) items are not available (False) A menu item may contain a check mark beside it (indicating that the item is checked—by default the Checked property is set to False Many computer users prefer to use keyboard shortcuts for selecting menu items

Standards for Windows Menus Follow Windows standards for applications Include keyboard access keys Use standards for shortcut keys, if used Place the File menu at left end of menu bar and end File menu with the Exit command Help, if included, is placed at right end of menu bar File Edit View Format Help When applications are written to run under Windows, programs should follow the Windows standards Plan menus so that they look like other Windows programs

Common Dialog Boxes Predefined standard dialog boxes for: Specifying colors and fonts Printing, opening, and saving Add appropriate Common Dialog components to display the dialog boxes that are provided as part of the Windows environment To use a common dialog component, add the component to the form, placing it in the component tray

Common Dialog Tools Pointer ColorDialog FontBrowserDialog FontDialog OpenFileDialog SaveFileDialog

Displaying a Windows Common Dialog Box Use ShowDialog method to display the common dialog box at run time ShowDialog only displays the dialog ColorDialog1.ShowDialog( ) FontDialog1.ShowDialog( )

Modal versus Modeless Windows A dialog box is said to be modal - means that it stays on top of the application and must be responded to Use the ShowDialog method to display a dialog box-it is a window displayed modally Modeless windows do not demand that there is a response Use the Show method to display a modeless window You have probably noticed that when you display a Windows dialog box it remains on top until you respond to it But in many applications you can display additional windows and switch back and forth between windows

Using the Information from the Dialog Box Code must be written to retrieve and use the choice made by the user in the common dialog box Example Color Dialog displayed User selects color and clicks OK-the selected color is stored in a property that can be accessed Color that is selected is stored in the Color property and can be assigned to another object such as a control You can also use the Font Dialog Box in much the same way and assign Font properties to the Front property of other objects on a form titleLabel.BackColor = ColorDialog1.Color

Setting Initial Values Before executing the ShowDialog method, assign the existing values of the object's properties that will be altered When the dialog box appears, the current values will be selected If the user presses Cancel, property settings for the objects will remain unchanged When a common dialog box for colors or fonts appears, what color or font do you want to display? It’s best to assign initial values before showing the dialog box FontDialog1.Font = .subTotalLabel.Font or ColorDialog1.Color = .BackColor

Creating Context Menus Shortcut menus that pop up when you right-click Items are specific to the component to which user is pointing, reflecting options available for that component or situation A ContextMenuStrip component is added and appears in the component tray below the form A context menu does not have a top-level menu, only menu items Application can have multiple context menus Context menus can be added to applications Creating a context menu is similar to creating a menu

Writing General Procedures A general procedure is reusable code which can be called from multiple procedures Useful for breaking down large sections of code into smaller units Two types Sub Procedure performs actions Function performs actions AND returns a value (the return value) Often programming situations exist in which multiple procedures perform the same operation—this conidtion can occur when the user can select either a button or a menu item to do the same thing Rather than retyping the code reusable code in a general procedure can be written and call it from both event procedures

Passing Arguments to Procedures Declare variable as local and pass to any called procedures – (can be module level but it makes the variable visible to all other procedures) If a sub procedure names an argument, any call to the procedure must supply the argument Name of the argument does not have to be the same in both locations Number of arguments, sequence and data type must match At time it may be necessary to use the value of a variable in one procedure and then again in a second procedure that is call from the first

Creating a New Sub Procedure In the Editor window enclose the lines of code with a set of Sub and End Sub statements To use the Sub Procedure, call it from another procedure Code in a Sub Procedure cannot be executed unless called from another procedure Private Sub ProcedureName( ) ' Statements in the procedure. End Sub VB.NET has choices other than Private for the access, such as Public, Friend, and Protected—Private can be used for all general procedures (key term)

Sub Procedure Example Sub Procedure Calling Procedure Private Sub SelectColor(incomingColor As Color) With ColorDialog1 .Color = incomingColor .ShowDialog( ) End With End Sub Sub Procedure Private Sub changeTitleButtonColor_Click( ) Dim originalColor As Color originalColor = titleLabel.ForeColor SelectColor(originalColor) titleLabel.ForeColor = ColorDialog1.Color End Sub Calling Procedure

Passing Arguments ByVal or ByRef ByVal -value Sends a copy of the argument’s value, original cannot be altered ByRef -reference Sends a reference to the memory location where the original is stored and therefore the procedure may change the argument’s original value can be altered If not specified arguments are passed by value When passing a value to a procedure it may be passed ByVal or ByRed

Writing Function Procedures In the Editor window enclose the lines of code with Private Function( ) and End Function statements Since the procedure returns a value a data type for the value must be specified To use the Function, Call it by using it in an expression Pass arguments ByVal or ByRef Programmers may need to calculate a value that will be needed in several different procedures or programs Functions also can be declared as Public, Protected, or Friend (introduced in later chapter) Private Function FunctionName( ) As Datatype ' Statements to execute. End Function

Returning the Result of a Function To return a value to the calling procedure set up a return value The return value will be placed by VB in a variable with the SAME name as the Function's name --OR-- Use the Return statement to return the value The main difference between coding a function procedure and coding a sub procedure is that in a function procedure a return value must be set; the return value is palced in a variable that VB names with the same name as the function name

Function Example Calling Procedure Function Private Function Commission(ByVal salesAmountDecimal As Decimal) _ As Decimal If salesAmountDecimal < 100D Then Commission = 0D Else Commission = 0.15 * salesAmountDecimal End If End Function Function Private Sub calculateButton_Click( ) Dim salesDecimal As Decimal salesDecimal = Decimal.Parse(salesTextBox.Text) commissionLabel.Text = Commission(salesDecimal.ToString("C")) End Sub Calling Procedure

Functions with Multiple Arguments Functions can receive one or more arguments (values) Sequence and data type of arguments in Call must exactly match arguments in function header Private Function Payment(ByVal rateDecimal As Decimal, _ ByVal timeDecimal As Decimal, ByVal amountDecimal _ As Decimal) As Decimal paymentLabel.Text = Payment(Decimal.Parse(rateTextBox.Text), _ Decimal.Parse(yearsTextBox.Text), _ Decimal.Parse(principalTextBox.Text)).ToString( ) End Function

Breaking Calculations into Smaller Units Projects with many calculations are easier to understand and write if calculations are broken into small units Each unit should perform one program function or logic block