GNVQ
Intermediate IT Optional Unit5
Tutors Sue Cahill and Colin Duley
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
To show a form use the method
For example:
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.
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.
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:
|
|
|
|