0 index
1 Modules
2 What do they contain?
3 How are they used?
4 Creation of global procedures
5 Scope map
6 Global procedures
7 Syntax
8 Parameters
9 Multiple forms
10 Show
11 Example
12 Modal switch
13 Hide
14 Startup form

outline
created using slideshow.cgi by Andy Harris















CSCI N331 Visual Basic: n331/vb15modules
1. Modules
  • Description of a module:
       - they are like separate files on a disk
       - they are like the code part of a form - no objects are attached
       - are saved on the disk with a .BAS extension



































CSCI N331 Visual Basic: n331/vb15modules
2. What do they contain?
  • Modules contain record definitions
  • GLOBAL variable declarations
  • Global procedures



































CSCI N331 Visual Basic: n331/vb15modules
3. How are they used?
  • Modules are used to declare GLOBAL variables
       - use the keyword GLOBAL in place of DIM
       - can only be used in the general area of a module
       - otherwise used just like DIM



































CSCI N331 Visual Basic: n331/vb15modules
4. Creation of global procedures
  • Because they are global, they can be called from any form, any procedure in the project
  • It is just like creating a new command
  • Can be used to store a library of useful subprograms (e.g., printing related)
  • Are created by choosing New Module from the File menu or hitting New Module button



































CSCI N331 Visual Basic: n331/vb15modules
5. Scope map



































CSCI N331 Visual Basic: n331/vb15modules
6. Global procedures
  • Are created in the general area of forms or modules
  • In forms, makes a form-level procedure
  • In modules, makes a global procedure
  • Can be called from within code - New command



































CSCI N331 Visual Basic: n331/vb15modules
7. Syntax
  • Sub ProcedureName (Parameters)
  • Creates a new section of the general area
  • Code can be written in this area



































CSCI N331 Visual Basic: n331/vb15modules
8. Parameters
  • "Instant" local variable(s)
  • They don't have to be declared
  • To call a procedure -simply use its name in code



































CSCI N331 Visual Basic: n331/vb15modules
9. Multiple forms
  • To create use New Form on the File menu or New Form button
  • Useful methods -
       -Show
       - Hide



































CSCI N331 Visual Basic: n331/vb15modules
10. Show
  • Syntax: FormName.Show 1
  • This action is modal
  • The FormName is the name of the form you have created in the project



































CSCI N331 Visual Basic: n331/vb15modules
11. Example
  • Second.Show 1
  • This loads Second into memory if it's not there and shows it to the user



































CSCI N331 Visual Basic: n331/vb15modules
12. Modal switch
  • If you end the show method with a 1, the form will be modal
  • The new form gets focus
  • The next code that is activated is in the form_load procedure of the second form
  • The control reverts to the original form after the second is closed
  • If you do not put a 1 at the end, the form shows up, but does not get the focus
  • The control of the program moves on to the next line of code in the first form



































CSCI N331 Visual Basic: n331/vb15modules
13. Hide
  • Syntax: FormName.Hide
  • Example: Second.Hide
  • This hides the named form and the control reverts back to the procedure that showed the form
  • Warning! Don't hide ALL the forms in a project!



































CSCI N331 Visual Basic: n331/vb15modules
14. Startup form
  • One form must be designated as the startup form
  • By default this will be the first form created
  • To change this, use the Project dialog under the Options Menu



































outline

Modules

What do they contain?

How are they used?

Creation of global procedures

Scope map

Global procedures

Syntax

Parameters

Multiple forms

Show

Example

Modal switch

Hide

Startup form