Programming In Visual Basic .NET

Slides:



Advertisements
Similar presentations
Multiple Forms, Standard Modules, And Menus
Advertisements

Using Macros and Visual Basic for Applications (VBA) with Excel
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Eight Sub and Function Procedures.
Advanced Microsoft Word Hosted by Jared Hoffman Topics Keyboard Shortcuts Customizing Toolbars and Menus Auto Format & Auto Correct Tabs Inserting Pictures.
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.
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.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 7- 1.
Chapter 5 - Menus, Sub Procedures, and Sub Functions  Menus - controls - properties and events –menu editor - create and change –defining menus - menu.
Creating Menu. Objectives Create a menu system for a form –Create a menu –Create a menu titles –Create a menu items –Create a submenu –Modify menu –Edit.
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)
Printing and Page Formatting ITSW 1401, Intro to Word Processing Instructor: Glenda H. Easter.
PYP002 Intro.to Computer Science Microsoft Word1 Lab 07 Creating Documents with Efficiency and Consistency.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Chapter 8: String Manipulation
Programming with Microsoft Visual Basic th Edition
Apply Sub Procedures/Methods and User Defined Functions
McGraw-Hill© 2007 The McGraw-Hill Companies, Inc. All rights reserved. 1-1.
CIS162AD - C# Methods, Menus, and Dialog Boxes 05_methods_menus.ppt.
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.
Copyright 2007, Paradigm Publishing Inc. EXCEL 2007 Chapter 7 BACKNEXTEND 7-1 LINKS TO OBJECTIVES Record & run a macro Record & run a macro Save as a macro-
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.
PMS /134/182 HEX 0886B6 PMS /39/80 HEX 5E2750 PMS /168/180 HEX 00A8B4 PMS /190/40 HEX 66CC33 By Adrian Gardener Date 9 July 2012.
Chapter 3 Introducing Visual Basic.NET. 3.1 Visual Basic.NET Windows Programming -Used to create Windows, Web, and Console applications -Uses predefined.
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 5 Menus, Common Dialog Boxes, Sub Procedures, and Function Procedures.
INSERT BOOK COVER 1Copyright © 2011 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Microsoft Office Excel 2010 by Robert Grauer, Keith.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Typing Application Introducing Keyboard Events, Menus, Dialogs and the Dictionary.
Microsoft Access Lesson 1 Lexington Technology Center February 11, 2003 Bob Herring On the Web at
Chapter 5 Menus, Common Dialog Boxes, and Methods Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
Tutorial 111 The Visual Studio.NET Environment The major differences between Visual Basic 6.0 and Visual Basic.NET are the latter’s support for true object-oriented.
Debugging and Menus Part07dbg --- Solving the problem, Debugging in Break time, Menus, Common Dialogs, and User-written methods.
VB Procedures. Procedures. Sub procedure: Private/Public Sub SubName(Arguments) … End Sub Private: Can only be accessed by procedures in the same form.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
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.
110-G1 Motivation: Within a program, may have to perform the same computation over and over Many programs share the same computation (e.g. sorting) To.
Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.
McGraw-Hill © 2009 The McGraw-Hill Companies, Inc. All rights reserved. Chapter 6 Multiform Projects.
McGraw-Hill/Irwin The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft Excel 2002 Lesson 2 Manipulating.
Microsoft Outlook 2010 Chapter 3 Managing Contacts and Personal Contact Information with Outlook.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. M I C R O S O F T ® Revising Presentation Text Lesson 3.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
A lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. a lesson approach Microsoft® PowerPoint 2010 © 2011 The McGraw-Hill Companies,
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Slide 1 Using Menu Bar & Common Dialog Boxes. Slide 2 Setting Up the Main Items v First open the form on which you want the menu located v Then start.
CHAPTER SIX Reducing Program Complexity General Sub Procedures and Developer-defined Functions.
Chapter 3 Automating Your Work. It is frustrating when you have to type the same passage of text repeatedly. For example your name and address. Word includes.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Eight String Manipulation.
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.
Copyright (c) 2003 by Prentice Hall Provided By: Qasim Al-ajmi Chapter 2 Introduction to Visual Basic Programming Visual Basic.NET.
Compunet Corporation Programming with Visual Basic.NET Working with Menus and Dialog Boxes Week 14 Tariq Aziz and Kevin Jones.
Creating New Forms Projects can appear more professional when using different windows for different types of information. Select Add Windows Form from.
Customizing Menus and Toolbars CHAPTER 12 Customizing Menus and Toolbars.
Visual Basic.NET BASICS Lesson 14 Menus and Printing.
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 7, Slide 1Starting Out with Visual Basic 3 rd Edition Chapter 7 Multiple Forms, Standard Modules, And Menus.
Using Procedures and Exception Handling
Brief description on how to navigate within this presentation (ppt)
Presentation transcript:

Programming In Visual Basic .NET Chapter 5 Menus, Common Dialog Boxes, Sub Procedures and Function Procedures Programming In Visual Basic .NET

<ALT><F> Menu <ALT><F> Menu Items © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

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 a click event Add MainMenu control to form Appears in the Component Tray, below form, where nondisplay controls are shown Words "Type Here" appear at the top of the form © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

Menus (continued) Type first Menu here MainMenu Control appears in Component Tray © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

Defining Menus To create the menus simply type where the words "Type Here" appear at the top of the form Include & symbol as you type to indicate keyboard access keys You are actually entering the Text property for a MenuItem object Change MenuItem object names in the Properties window and follow consistent naming conventions © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

Submenus Pop up to the right of a menu item 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 © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

Submenus (continued) © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

Separator Bars Used for grouping menu items according to their purpose Visually represented as a bar across the menu Create using one of two methods Typing a single hyphen for the text Right-click on Menu Designer where you want a separator bar and choose Insert Separator © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

Coding for Menu Items Double-click any menu item to open the item’s click event procedure Write code for the click event procedure © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

Modifying Menu Items Right-click the Menu Bar to: Delete Insert New Insert Separator Edit Names Displays menu item Name property rather than Text property on form Drag and Drop menu items to new locations © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

Menu Properties Enabled property, True/False Checked property, True/False Used to indicate current state of menu item that can be turned on and off Create keyboard shortcuts In Properties window for menu item, select the Shortcut property Make choice from drop-down list © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

Standards for Windows Menus Follow Windows standards for applications Include keyboard access keys Use standards for shortcut keys, if used Place File menu at left end of menu bar and end File menu with Exit Help, if included, is placed at right end of menu bar File Edit View Format Help © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

Common Dialog Boxes Predefined standard dialog boxes for: File Opening and Saving Font and Color selection Printing and Previewing Add appropriate Common Dialog control to form Appears in the Component Tray © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

Common Dialog Controls OpenFileDialog SaveFileDialog FontDialog ColorDialog PrintDialog PrintPreviewDialog © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

Common dialog controls Component tray © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

Displaying a Windows Common Dialog Box Use ShowDialog method to display the common dialog box at run time ShowDialog only displays the dialog, it does not do anything else ColorDialog1.ShowDialog( ) FontDialog1.ShowDialog( ) © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

With OpenFileDialog1 .ShowDialog() End With Code © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

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 Code must be written to apply the selected color to the object(s) titleLabel.BackColor = ColorDialog1.Color © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

Color and Font Dialogs © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

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 FontDialog1.Font = subTotalLabel.Font or ColorDialog1.Color = Me.BackColor © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

Creating Context Menus Shortcut menus that pop up when you right-click Are specific to the component to which user is pointing, reflecting options available for that component or situation A context menu does not have a top level menu Application can have multiple context menus © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

Creating Context Menus (continued) Add ContextMenu component to the form Appears in the Component Tray Click on the words "Context Menu", at the top of the form, the words "Type Here" appear Click on the words "Type Here" and proceed as you did for the main menu © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

Connecting the Context Menu to a Form or Object Set the form or object’s ContextMenu property to the name of the ContextMenu If there is more than one context menu defined, choose from the list Add to the Handles clause of a MainMenu item to use the same procedure for a related ContextMenu item © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

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) © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

Creating a New Sub Procedure In the Editor window enclose the lines of code with a set of Private 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 © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

Passing Arguments to Procedures (page 205) Declare variable as local and pass to any called procedures If a sub procedure names an argument, any call to the procedure must supply the argument Name of local variable does not need to match name in sub procedure argument list Number of arguments, sequence and data type must match © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

Passing Arguments ByVal or ByRef ByVal (default) Sends a copy, original cannot be altered ByRef Sends a reference to the memory location where the original is stored and therefore the original can be altered Examples page 206 © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

Sub Procedure Calling Procedure Sub Procedure Example 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 © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

Writing Function Procedures In the Editor window enclose the lines of code with Private Function( ) and End Function statements To use the Function, Call it by using it in an expression Pass arguments ByVal or ByRef Private Function FunctionName( ) As Datatype ' Statements to execute. End Function © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

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 © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

Function Function Example Calling Procedure 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 © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

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 © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

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 © 2005 by The McGraw-Hill Companies, Inc. All rights reserved.

© 2005 by The McGraw-Hill Companies, Inc. All rights reserved.