Presentation is loading. Please wait.

Presentation is loading. Please wait.

Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San.

Similar presentations


Presentation on theme: "Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San."— Presentation transcript:

1 Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San Diego

2 Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Ch6: Multiple Forms  Multiple forms  Show and Hide methods for forms  Standard code modules  Variable scope in multiform projects  An About Box form  Splash screen  Set the startup form

3 Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Multiple Forms  Creating new forms  Adding and removing forms  Hide & Show methods  Load & Unload statements  Referring to objects in other forms –code in one form cannot “see” obj. in other forms –reference: FormName!ObjectName.property

4 Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Multiple Forms  First form is startup form. –By default, it is the first one created –You can set startup form in Project, Properties  Create form: –Project, Add Form –Select form type  You can add a form to project from existing form

5 Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Adding/Removing Forms  All the information in a form resides with the form: controls, properties, code, variables  Add existing form: Project, Add Form and then click the existing tab  Remove a form: Project, Remove File

6 Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Hide and Show methods  You display a form with the show method: frmAbout.Show  General form is formname.Show –where style can be 1 (modal) or the default value 0 (nonmodal)  User must respond to Modal form & cannot click another form in same project  Hide a form: frmAbout. Hide

7 Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Form Load & Activate Events  The first time a form is displayed, it triggers a form load event followed by a form activate event  Load calls the module into memory  Activate occurs when the form receives control  Subsequently, activate but not load events trigger when form is shown

8 Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Unload/Load Statements (cont'd)  Only time you might want to load a form is when you want to load a form but display it later.  The Me keyword refers, always, to the currently active form: Unload Me Me.Hide

9 Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Referring to Other Forms’ Objects  You can refer to txtName in another form called frmSummary this way: frmSummary!txtName = … or frmSummary!txtName.Font.Name =...  This implies that control names are unique within a form but need not be unique across forms.

10 Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Standard Code Modules  Public procedures are“visible” to all forms  Public variables are visible to all forms  SCM has the extension.BAS  Create SCM: Project, Add Module  DIM variables in the code module are visible to all procedures in the module, but not to procedures in the form modules.

11 Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Variables & Constants in Multi- form Projects  Scope of variables: –Local: available inside a procedure –Static: inside procedure, but remembered –Module level: available anywhere in a form –Global: available across forms--anywhere  Global variables declared with Public  Variable prefix naming conventions: m for module, g for global  Scope a variable as narrowly as possible

12 Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill An About Box  Acts like a Windows Help|About box  Often displays information about the programmers, designers, and so on  An about box is simply a modal form with an OK button and label boxes displaying information  You can use VB’s About Dialog template

13 Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill A Splash Screen  Splash screen displays while product loads  Create: Project, Add Form, then select Splash Screen  Splash screen loads first instead of main form  Place splash screen load statement in Sub Main procedure in Standard Code Module

14 Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Setting the Startup Form/Proc.  By default, the first form you create in a project is the startup form  You can set the startup form in the Project Properties menu (Project menu)

15 Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Hands on Programming Example  Programming example is a multi-form Coffee Sales example with these forms: –Splash screen –Main form –Summary form –About box  Main form called from splash screen

16 Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Programming Hints  Make form run maximized window by setting the WindowState form property to 2-Maximized  In design time, close extra windows to maximize your view of form  Clicking a form's Close button halts execution

17 Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Summary (1)  Projects can have unlimited # forms  First form displayed is the startup form  You can use forms from one project in another one  Show/Hide are form methods  Modal form requires a response; and, execution halts until response received

18 Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Summary (2)  Load statement loads forms but does not display them  Me refers to currently active form  Refer to object in another form with form name as prefix  SCM contains public variables and public sub procedures that are global to project

19 Copyright© 2000 by the McGraw-Hill Companies, Inc.Irwin/McGraw-Hill Summary (3)  Public can appear only in the General Declarations section of a module—place it in SCM only by convention  Static variables are local but with “memory”  Program execution can begin in a sub procedure called Main located in Standard Code Module


Download ppt "Irwin/McGraw-Hill Copyright© 2000 by the McGraw-Hill Companies, Inc. PowerPoint® Presentation to accompany prepared by James T. Perry University of San."

Similar presentations


Ads by Google