| Lecture Topic: |
Forms, Properties, Controls, &
Variables |
| Objectives: |
As a result of this instruction and after having
completed the associated readings and exercises students will understand or be able to:
- See lecture objectives for the week
|
| Readings: |
Murach Chapters 1, 2, 3, & 4 |
| Exercises: |
- GPA Calculator:
- Create a form with which you can enter all of the information for
one class needed to calculate your GPA as well as the course number
("ISM 4212", etc.), course title, credit hours, letter grade, and letter
grade points (you would enter 4 for an A, 3 for a B, etc.–later we will
learn a way to enter the letter grade and automatically look up the
grade points).
- Add a result label and a button and set up the program so that
pressing the button will multiply the credit hours times the grade
points to give the total grade points for the course.
Multiplication can be accomplished with the VB code
destinationValue = value1 * value2
- Ensure that you use conversion techniques to translate the numbers
read from text boxes into appropriate numeric values.
- Use the View | Tab Order technique to set the tab order for the
controls on the form. Test the tab order.
- Set hot keys for all of the controls.
- Add an exit button to the form and have it end the program.
- Introducing Variables
- Modify your program so that the number of credit hours earned is
stored in a form-level variable that will retain its value while the
program is running. This capability should be added to the button
click event you used above. (This can be done with code like:
VariableName = VariableName + NewValue or
VariableName += NewValue
- Have the accumulating credit hours display in a label whenever they
are updated.
- Rewrite your button click event so that before multiplication is
performed on the values in the text boxes the values are stored into
numeric variables.
- Working with form and control properties: We are going to have our
form include some controls that won't always be available.
- Make a note of the Height property of your form.
- Add a button toward the bottom of the form and give it the label
"Details >>" (including the two greater than signs). Create a
second button and give it the label "<< Details".
- Lengthen your form by dragging the bottom downward. Add some
controls in this new area (what they are doesn't matter much).
Also make a note of the Height property of the form at this size.
Then reset your form so that the Height is back to the original height
and the new controls are no longer visible.
- Write code in your >> button to reset the form height property to
the second size AND to set the Visible property of that button to False
AND set the Visible property of the << button to True.
- Write code in your << button to reset the form height property back
to its original height (hide the new controls), set the Visible property
of the << button to False, and set the Visible property of the >> button
to True.
- In design time, set the Visible property of the << button to False
and then drag it so it is directly on top of the >> button! (You
will still see both buttons in design time but see what happens when you
run the program.)
If you ever need to select a control that is hidden by another one you
can do this using the drop-down list of controls at the top of the
properties window.
- If you have time, rewrite this section of the project so that
instead of changing the form size the buttons toggle the Enabled
property of the new controls on and off (start with them off in design
time). Still use the same two buttons and toggle them to be
visible/invisible in the same location but the new controls will always
be visible, just disabled.
- Commenting–Properly comment your code according to the style used in
the sample programs.
|
| Lecture Notes*: |
See lecture notes and sample programs for this week's class sessions |