PROGRAMMING WITH
MULTIPLE FORMS

WHY DO MOST VB PROGRAMS USE MULTIPLE FORMS? Visual Basic programs with any degree of complexity are best done using more than one form. It becomes increasingly difficult to crowd many different objects onto one form in a complex program.

It is easy to move between forms within a program. There are several items to consider.

  1. TO ADD ADDITIONAL FORMS:
    select from the Visual Basic menu (along the top) PROJECT then ADD FORM then NEW or EXITING and OPEN

  2. WHICH FORM WILL LOAD FIRST?
    To change this, select from the Visual Basic menu (along the top) PROJECT then projectname properties (the bottom item in this list) then select the desired form name in the START UP OBJECT WINDOW

  3. VARIABLES DECLARATION
    Any variables you need to have carried forward to the second form must be declared as a public variable. Read the page Declaring Variables for details on how to declare public variables.

    To summarize: this is done by selecting from the Visual Basic menu (along the top) PROJECT then ADD MODULE then NEW and OPEN.
    The variable is then declared under "general" section: ie:

    public studentmark as integer.

    This will declare a variable named "studentmark" as a integer which will be in effect for all forms in the program.   If a public variable is declared, you do not need to declare it again on individual forms.


  4. MOVING BETWEEN FORMS USING Load/Show/Unload COMMANDS
    If the program is in frmFORM1 and you wish to move to frmFORM2, just use the commands:

    load frmFORM2
    frmFORM2.show
    unload me

  5. MOVING BETWEEN FORMS USING FORM visible PROPERTY
    (formname.visible = true or formname.visible=false)

    details:
    Within a procedure, ensure that both forms are loaded at the start using the usual commands.

    ie:
    If frmFORM1 loads initially when you run the program (see #2, above), then the command is just:

    load frmFORM2
    frmFORM2.visible = true
    frmFORM1.visible = false
    etc.