GNVQ Intermediate IT Optional Unit5

Tutors Sue Cahill and Colin Duley



GNVQ IT Intermediate - Visual Basic Notes 5

More Forms

There will be occasions, when writing a VB program, when you will require more than one form.  In the example program provided in this assignment, the start up form provides the user with the facility to enter data, in this case information about students, their names and marks awarded for a course.

A second form is used to display the certificate to be awarded to the student.  This form shows the student’s name, the level and name of the award.  On the form is a picture of a Scroll and the option to print the Certificate is provided.

To add a new form to a VB program: -


Design your new form, adding controls and code as required



Some new statements or methods are introduced here.

To show a form use the method

To hide a form use the method For example, if you have a main form and you wish the user to see the second form and not the first, you could use the following code To send a copy of a form to the printer you can use the following method (You might find you need to adjust the design and scale of your form for it to print properly)


To hide buttons that reside on a form, but which you don’t want to appear on the print-out of that form, simply set their visible property to false before you ask to print the form.  Then, set them back to visible immediately afterwards.

For example:



Using variables across forms.

Variables declared in the General Declarations of one form are not known in other forms, so any value that is set in one form will not pass to the other.  If you wish a variable to be known on other forms, then you need to declare them in a module – they will then have a scope throughout the forms in that module.



To add a module:


You will then see the following displayed in the project window

Now go to the General Declarations section of the Module and declare the variables you need using the word Public (not Dim) as shown on the screen on the previous page.



Control properties using multiple forms.

To reference the value of a control property from a form other than the form on which the control resides, you must give the form name as well as the control name and property.

For example, you might want to pass the text entered into a text box on one form to the caption of a label box on a second form.  From the second form, the code could look like this:

where lblName is the name of the label box on the second form and txtName is the name of the text box on the first form.

 Top of Page
Home Page 
Query for Tutor?