LAB 2.0 - Multiple Forms
Goals:
w Use on-line help
w Permanently declare Option Explicit
w Display messages
w Work with multiple forms
w Copy from the hard drive to the floppy drive
__1. Begin a new program
w Start up Visual Basic again
w Name the project Many and the form frmMain
w Choose an appropriate place to save this program
w After choosing an appropriate place, save the project
in a new
folder called Multiples.
__2. Become acquainted with
the on-line help system.
w Open the online help window
v Click on Help in the menu bar
v Choose Index... from
the menu items.
v If the Active Subset is
not Visual Basic Documentation,
choose
it.
v If the Index tab is not chosen, choose it
v In the open windowlet begin typing visible
property until
that
entry is highlighted.
v Click on Display
w Find
information on the visible property
v When the Topics Found window
appears, check to make
sure Visible
Property / Visual Basic Reference is highlighted.
v Click on Display again.
w Explore a typical help window
v Click on See Also
v List two topics related to the visible property
v Click on Example
v In the code displayed, what object is made visible?
Invisible?
v Click on Applies To
v Can a label be made visible/invisible? A Textbox?
v In the discussion of Visible Property, find the
phrase
Boolean
expression and click
on it. What is a Boolean
expression?
v How is the visible property related to the Hide
and Show
methods?
w Using online help, find out how many methods operate
on the
Textbox control.
__3. Choose Option
Explicit as a permanent feature
w From the Tools menu choose Options...
w If the Editor tab is
not chosen, choose it
w Notice a list of Code Settings,
some with a check mark by them.
w Make sure there is a check mark by Require
Variable Declaration
If
there is no check mark there, click in the little window
Be
careful not to disturb any other settings!
w Click on OK
__4. Begin learning to work
with multiple forms
w Type Baseball for the caption of frmMain.
w Place 3 command buttons on frmMain, naming
them cmdExit,
cmdHomeRuns
and cmdStrikeOuts
w Give them appropriate captions
w Add 2 forms to your project
v Click on the Add Form icon in the toolbar (2nd from left)
v Make sure the New
tab is chosen and Form is highlighted;
click on Open
v Name the new
forms frmHR and frmKO and give them
appropriate captions.
w Save these forms as part of your project
v Click on frmHR
in the Project Explorer to highlight it
v Choose Save frmHR As... from the File menu
v Notice that the
value of Save
In: is the folder Multiples
v Click on Save
v Now save frmKO
the same way
v Finally, choose Save Project from the File menu
[Notice, this requires no further response from
you].
__5. Create ability to go
from form to form
w First, notice that as you (single)click on a form in
the Project
Explorer window,
that form’s properties are displayed; and as you
double-click on
each form, the form itself appears in the Form
Design window.
w Change the visible property of frmHR and frmKO
to False.
w Write code for the command buttons of frmMain.
v For cmdExit
End
v For cmdHomeRuns
frmMain.Visible
= False
frmHR.Visible
= True
v For cmdStrikeOuts
frmMain.Visible
= False
frmKO.Visible
= True
w Add command buttons to both frmHR and frmKO,
naming them
both cmdBack. Why is there no name conflict? Give them
appropriate
captions.
w Write code for the first of these buttons
frmHR.Visible
= False
frmMain.Visible
= True
w Write code for the other button. What do you think that code
should be?
w Now test out your program.
__6. Now add some interest to
your program.
w On frmHR place two command buttons, cmdSosa
and
cmdMcGwire
and one label, lblHowMany.
Delete the caption
for the label and give appropriate captions
to the command buttons.
w Write code for the command buttons.
v For cmdSosa
lblHowMany.caption
= “66”
v For cmdMcGwire
lblHowMany.caption
= “70”
w Again, test out your program.
w Now do something similar for frmKO. Here is some information
you can use.
Career
strikeouts::
Nolan Ryan - 5714
Steve Carlton - 4136
w Run your program to test it.
w Exit Visual Basic.
When you are asked about saving, answer Yes.
__7. Copy your program to a
floppy.
w Insert a floppy in the floppy drive.
w Starting at MyComputer, open the folders
leading to Multiples
(but do not
open Multiples!).
w Find the MyComputer window and open 3-1/2
Floppy
w Drag the Multiples folder into the 3-1/2
Floppy window.
Your program is
now saved both on the hard drive and the floppy.
__8. Congratulations! You have completed a difficult
assignment. Treat
yourself to some macadamia nuts.