Multiple Forms Standard Code Modules - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Multiple Forms Standard Code Modules

Description:

have scope - one form cannot see code in another (unless it is declared Public) ... Unload frmName - will remove a form from memory ... – PowerPoint PPT presentation

Number of Views:85
Avg rating:3.0/5.0
Slides: 13
Provided by: hges
Category:

less

Transcript and Presenter's Notes

Title: Multiple Forms Standard Code Modules


1
Multiple FormsStandard Code Modules
chapter
SIX
2
Multiple Forms in Project
Project
Form1
Form2
3
Multiple Forms in Project
  • Forms
  • have scope - one form cannot see code in another
    (unless it is declared Public)
  • reusable - have frm extension and can be used in
    other projects
  • Startup form
  • first form a project displays
  • Creating
  • Add Form under Project
  • New or Existing

4
Multiple Forms in Project
  • Project Menu Add Form choose type
  • Project Menu Remove Form
  • highlighted form in project explorer will be
    removed

5
Loading Forms
  • Forms are loaded the first time shown
  • A Form Load Event occurs when form loaded -once
    only, unless forms are unloaded and then loaded
    again.
  • A Form Activate Event occurs each time a form is
    shown subsequently
  • discuss use of these two events

6
Explicitly Loading/Unloading a Form
  • Load frmName - will load a form, but not show it
  • Unload frmName - will remove a form from memory
  • use when form will no longer be used by program
    (i.e. startup or splash screen form)
  • Unload Me
  • Me is variable referring to current form

7
Showing Forms
  • Show Method
  • FormName.Show style
  • style vbModal (user must respond to form -
    click etc.
  • Important - NO OTHER CODE in PROGRAM will be
    executed until response and form hidden or
    unloaded
  • style vbModeless (user can switch to other
    forms in project)
  • Code in project after Show will continue to be
    executed
  • frmAbout.Show vbModal
  • frmSummary.Show vbModeless

8
Hiding Forms
  • Hide Method
  • Used to remove form from screen (remains in
    memory)
  • Generic FormName.Hide
  • frmAbout.Hide
  • Me.Hide

9
Referring to Objects on Other Forms
  • Generic frmName.ObjectName.Property
  • So could I set up properties (ie label captions)
    before I showed a form?
  • What does this do in terms of scope of variables
    used in display?
  • VERY IMPORTANT - review Guidelines on page 216
    for declaring variables and constants

10
Standard Code Modules
  • A file with a .BAS Extension
  • Not associated with a particular form - contains
    only VB Code (no form/objects)
  • Has a general declarations section and same
    structure as any form module
  • Procedures and Functions that need to be used by
    multiple forms could reside in code module
    (define as Public)

11
Standard Code Modules (2)
  • Often contains a Sub Main Procedure which could
    start up the project (rather than a particular
    form)
  • A Splash screen could be shown via the Sub Main
    Procedure and the next form could be explicitly
    loaded while the flash shows
  • Sub Main ()
  • frmSplash.Show vbModeless
  • Load frmMain
  • End Sub

12
Standard Code Modules (3)
  • Must set SubMain as start up form (defaults to
    first form in project)
  • Project Menu Project Properties
  • (Startup Form Drop Down -
  • Choose Startup Form or Sub Main)
Write a Comment
User Comments (0)
About PowerShow.com