Multiple Forms and Standard Modules

Slides:



Advertisements
Similar presentations
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 7- 1 STARTING OUT WITH Visual Basic 2008 FOURTH EDITION Tony Gaddis.
Advertisements

Multiple Forms, Standard Modules, And Menus
Chapter 7: Sub and Function Procedures
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.
Visual Basic Project Files:.VBP file: Project File: a small text file that contains the names of other files in the project, as well as some information.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 06.
Addison Wesley is an imprint of © 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 7 Multiple Forms, Modules,
VBA Modules, Functions, Variables, and Constants
Using Visual Basic 6.0 to Create Web-Based Database Applications
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 7- 1.
CVEV 118/698 Visual Basic Lecture 3 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar.
Multiple Forms & Procedures. Form Methods: –Show, Hide, Activate, Close Events: –Load, Activated, Closing, Closed.
Macros Tutorial Week 20. Objectives By the end of this tutorial you should understand how to: Create macros Assign macros to events Associate macros with.
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,
Multiple Document Interface (MDI) application
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,
Copyright © 2014 Pearson Education, Inc. Chapter 7 Multiple Forms, Modules, and Menus.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
WORKING WITH MACROS CHAPTER 10 WORKING WITH MACROS.
Chapter 8: String Manipulation
Tutorial 7: Sub and Function Procedures1 Tutorial 7 Sub and Function Procedures.
Tutorial 7: Sub and Function Procedures1 Tutorial 7 Sub and Function Procedures.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Seven Sub and Function Procedures.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Tutorial 11 Using and Writing Visual Basic for Applications Code
McGraw-Hill/Irwin Programming in Visual Basic 6.0 © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Update Edition Chapter 6 Multiple Forms.
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
Microsoft Visual Basic 2008 CHAPTER NINE Using Arrays and File Handling.
Microsoft Visual Basic 2005 CHAPTER 9 Using Arrays and File Handling.
Multiple Forms, Standard Modules, And Menus
Chapter 6 Understanding the Structure of an Application: Procedures, Modules, and Classes.
Using Arrays and File Handling
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.
Multiple Forms, Container Controls, AddHandler This presentation is based on the Forms and ContainerControls VB Projects 1.
Copyright © 2001 by Wiley. All rights reserved. Chapter 5: The Repetition Process in Visual Basic Event Driven Loops Determinate Loops Indeterminate Loops.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
Chapter 9 - VB.Net by Schneider1 Chapter 9 – Additional Controls and Objects 9.1 List Boxes, Combo Boxes, and the File-Opening Control The List Box Control.
 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.
11-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
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.
Visual Basic Programming Chapter Six Notes Repetition and the Do Statement ADDING ICONS TO YOUR FORM –It is possible to add an ______________ to your title.
Copyright © 2012 Pearson Education, Inc. Chapter 9 Classes and Multiform Projects.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 7 1 Microsoft Office FrontPage 2003 Tutorial 8 – Integrating a Database with a FrontPage.
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.
Copyright (c) 2003 by Prentice Hall Provided By: Qasim Al-ajmi Chapter 2 Introduction to Visual Basic Programming Visual Basic.NET.
Unit 6 Repetition Processing Instructor: Brent Presley.
Chapter 13 Copyright 2000 All rights reserved 1 Chapter 13 Object-Oriented Programming.
Visual Basic.NET Programming for the Rest of Us Keith Mulbery Utah Valley State College.
Creating New Forms Projects can appear more professional when using different windows for different types of information. Select Add Windows Form from.
More Visual Basic Code: if-then-else, for loops Controls: Multiple forms, List Boxes, Radio buttons, frames,
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.
Chapter 7, Slide 1Starting Out with Visual Basic 3 rd Edition Chapter 7 Multiple Forms, Standard Modules, And Menus.
PictureBox, MessageBox, Multiple Forms, Splash Screens and Timers
Chapter 1: An Introduction to Visual Basic 2015
Multi-form applications and dialogs
Chapter 6 Multiform Projects
Multiple Forms, Modules, and Menus
Lecture Set 11 Creating and Using Classes
Object-Oriented Programming: Inheritance and Polymorphism
Presentation transcript:

Multiple Forms and Standard Modules Chapter 7

Form Names and File Names Default Name Property: Form1 Default File Name: Form1.vb Code stored in the .vb file Should assign descriptive form names for multiple-form programs Need to do more than change the Name property: Also change file name Also change Startup Object Chapter 7 - Part 1

Default File Name and Name Chapter 7 - Part 1

Changed File Name and Name Must keep .vb filename extension. Chapter 7 - Part 1

Adding a Form If program crashes because it can’t find a form, you might need to add it again: Choose Project | Add Existing Item or click and click Add Existing Item or press Shift + Alt + A. Choose .vb filename. Click Open. Chapter 7 - Part 1

Removing a Form Right-click form in the Solution Explorer window Choose Delete from the shortcut menu to remove the form from the project and delete the .vb file. Choose Exclude From Project to remove the .vb file from the project but not delete it. Chapter 7 - Part 1

Startup Object (p. 405) Right-click Project name (in Solution Explorer window) and choose Properties. …or… Choose Project | Properties. Chapter 7 - Part 1

Startup Object Click Startup object drop-down arrow and choose form name to be first object (form) that appears. Chapter 7 - Part 1

Add Form Click Add New Item on toolbar. Keep the .vb extension Chapter 7 - Part 1

Switching Between Forms Active Form Code window for frmStates form frmstates form Chapter 7 - Part 1

Form File Contents Coding Class declaration Program structure describing object’s properties and methods. All objects (such as form, list box, etc.) have properties (such as Name) and methods (such as AddItem). Name stored in form’s Name property Code between Public Class and End Class belong to class declaration for form. Chapter 7 - Part 1

The Class Declaration… Does not create the form. Describes the form. Acts like a house blueprint. Describes the form (house). Used to build an instance of the form (house). (see illustrations on p. 406). Creates 1+ instances of the form; use instances to display form onscreen. Create class at Design time. Instantiate class at Run time. Chapter 7 - Part 1

Instance of Form 1st step to display form: create an instance. Dim ObjectVariable As New ClassName() ObjectVariable Name that refers to instance of form, sort of like an alias (not name of form itself though) Holds memory address of object (form) so that you can use it ClassName() Form’s class name—the name used in the Name property for a form Chapter 7 - Part 1

Example Dim errorForm As New frmError() Does not actually display form errorForm is object variable name that creates instance of actual form frmError is the class (name) of the actual form As New causes instance of the form to be created in memory Memory address assigned to object variable name errorForm Does not actually display form Chapter 7 - Part 1

ShowDialog Method Modal method (most common) No other form can receive focus until the modal form is closed. Forces user (or timer) to acknowledge active form ObjectVariable.ShowDialog() errorForm.ShowDialog() Chapter 7 - Part 1

Show Method Modeless form ObjectVariable.Show() errorForm.Show() Allows user to switch focus to another form while the modeless form is displayed ObjectVariable.Show() errorForm.Show() Chapter 7 - Part 1

Close Method Closes a form and releases it from memory. Me.Close() Me—current instance of the form; refers to itself Close—closes current instance Use to close a form in a multiple-form program without terminating the application Chapter 7 - Part 1

Hide Method Removes form from the screen. Keeps form in memory; does not release it. Acts like changing form’s Visible property to False. Chapter 7 - Part 1

Other Events Load Activated Triggered immediately before a form displays. Example: populate a list box Activated Triggered when user switches to a form from another form. Triggered when for is initially displayed—after the Load event. Base Class Events (class name drop-down) Activated (method drop-down) Chapter 7 - Part 1

Closing Events Triggered as form is being closed but before it finishes closing. Useful to ask user if really wants to close form Event procedure parameter list includes ByVal e As System.ComponentModel e has Boolean property named Cancel True—prevents form from closing False—continues closing form Chapter 7 - Part 1

Closing, Continued Yes and No buttons DialogResult.Yes Set e.Cancel property to False to close form Otherwise (i.e., DialogResult.No) Set e.Cancel property to True; prevent closing Chapter 7 - Part 1

Closed Event Trigged after a form closes. Does not prevent a form from closing; only responds once the form is closed. Refer to p. 415 for more information. Chapter 7 - Part 1

Accessing Objects on Different Forms Default Controls are on same form as the statement that accesses it. lblOutput.Text = FormatCurrency(decTotal) Allowance Write code to access objects on different forms Dim resultsForm As New frmResults() resultsForm.lblOutput.Text = decTotal Chapter 7 - Part 1

Class-Level Variables Accessible to all statements on that form. Not accessible, by default, to statements on other forms. Class-level variables are private by default Accessible outside the file containing the class, use the Public key word: Public decTotal As Decimal Chapter 7 - Part 1

Procedures Private Public (default setting) Executable only from same form Public (default setting) Also executable by statements outside of the form Chapter 7 - Part 1

Standard Modules File (.vb) containing code Variable declarations Procedures Functions Not associated with a particular form Useful to organize code in multi-form projects Assign descriptive names (p. 423) Add a standard module (p. 424) Chapter 7 - Part 1

Private and Public Procedures Accessible by statements only inside that module Public Also accessible by statements outside that module Default if access specifier not provided Chapter 7 - Part 1

Module-Level Variables Module variable not declared within a procedure or function. Accessible by an sub procedure or function in the module. Not accessible to statements outside the module if declared with Dim or Private (module scope). Accessible to statements outside module if declared with Public (global scope). Use g_ prefix for global variables. See warning on p. 426. Chapter 7 - Part 1

Tutorials Tutorial 7-1 Tutorial 7-2 Tutorial 7-3 Modal and Modeless Multiple Forms Tutorial 7-3 Standard Module Chapter 7 - Part 1