IE 212: Computational Methods for Industrial Engineering Summer 2015

advertisement
IE 212: Computational Methods for Industrial Engineering
Summer 2015
Homework #4: Writing sub procedures
Tuesday, July 14th, 2015
IMPORTANT NOTES
To obtain full credit in this homework, you must:

Submit a single Excel file via The Engineering Accounts & Classes (T.E.A.C.H.) homepage
(http://engr.oregonstate.edu/teach) before the beginning of the lecture session on Tuesday,
July 14th, 2015 at 1:00 PM. Late submission is not allowed.
- Before submitting your solution file via T.E.A.C.H., make sure that the sample data
provided for each problem is in the format it was before you tested your sub procedures.
This will simplify the grading process.

Submit a hard copy of the last page included in this document at the beginning of the lecture
session on Tuesday, July 14th, 2015.
- Do not forget to add your name electronically to this page.

Solutions for each individual problem should be prepared in separate worksheets.

Make sure to follow good programming practices. In particular:
 Add comments to document your code, and
 Use indentation to make your code more readable and easier to grade.
PROBLEMS
Open a blank Excel workbook and save it as a MACRO-ENABLED file using the naming convention
“YourLastName_Hmw4.xlsm.” Your workbook must contain only two worksheets named "Prob1"
and "Prob2", respectively. In the Visual Basic Editor (VBE), insert a new module into the Project
Explorer and write (do NOT record) all your sub procedures inside this module.
Problem 1 (20 pts)
Manually create a data table exactly as shown in Table 1 into worksheet "Prob1". You can format the
cells manually (i.e., not via code) in Excel. The upper left corner of Table 1 (i.e., the label "Calendar
Year") should be entered in cell B2.
Table 1. Data for Problem 1.
Write a single sub procedure named Marine_Stats that will format the data and calculate the values
as described in Table 2.
Table 2. Data Formatting Instructions for Problem 1.
Labels
(I2:I4)
Total Vessel
Calls
Smallest
Automobile Units
Average Grain
Tonnage
Calculations
(J2:J4)
Cell Fill Color
(I2:I4)
(J2:J4)
Sum
Minimum
Average
Yellow
None
Blue
Green
Font Color & Type
(I2:I4)
(J2:J4)
Blue,
Underlined
Black, Bold,
White, Bold
Italic
Black, Italic
2
SOLUTION REQUIREMENTS:
a. The Offset property of the Range object MUST be used to position all labels and calculations in
their respective cells. You may use any cell in the worksheet "Prob1" as the base cell (i.e., 0th row
and 0th column cell) when using the Offset property.
b. Assign the sub procedure Marine_Stats to a rectangular shape button. The caption of the
rectangular shape button should read “Display Statistics”. The rectangular shape button should be
visually appealing and its upper left corner should be aligned with the upper left corner of cell L2.
c. After the rectangular shape button is clicked, the display of the first calculation (i.e., sum of vessel
calls), its label, and corresponding formats should be delayed three seconds. The display of every
subsequent calculation (and corresponding label and formats) should then be delayed two seconds
from the previous result.
d. The text “COMPLETE!” should be displayed in cell I6 one second after the last calculation is
displayed. Use capital letters and BOLD font style for this legend.
e. Range I2:J6 should be cleared automatically by your procedure every time it is run (Hint: Consider
the timing of this step and its effect on the functionality of your application).
f. You must use the With construct to make your code more readable.
g. Your sub procedure should end by selecting cell A1.
3
Problem 2 (30 pts)
Manually create a data table exactly as shown in Table 3 into worksheet "Prob2". You can format the
cells manually (i.e., not via code) in Excel. The upper left corner of Table 3 (i.e., the label "Club
Name") should be entered in cell B2.
Table 3. Data for Problem 2
SOLUTION REQUIREMENTS:
1. Write a sub procedure named English_PLeague that will:
a. Use the Columns property of the Range object to give each column in Table 3 its own
background color. You are at liberty to pick the color for each column from Red, Blue, Green,
Yellow, Cyan and Magenta. Note that Black and White are NOT acceptable colors to fulfill this
requirement.
b. Using the End property of the Range object:
 Copy the data column labeled “Club Name”. Paste these data in range J2.
 Copy the data column labeled “Games Played”. Paste these data in range K2.
 Copy the data column labeled “Points”. Paste these data in range L2.
c. Assign the sub procedure English_PLeague to a rectangular shape button. The caption of the
rectangular shape button should read “Summary Table”. The rectangular shape button should be
visually appealing and its upper left corner should be aligned with the upper left corner of cell
B16.
d. Ensure that no revolving border remains after executing any copy-pasting operations.
e. Ensure that no excessive flickering occurs when you run your sub procedure.
f. Your sub procedure should end by selecting cell A1.
2. Write a sub procedure named Clear_English_PLeague that will:
a. Clear range J2:L12.
b. Remove the background color from range B2:G12.
c. Assign the sub procedure Clear_English_PLeague to a rectangular shape button. The
caption of the rectangular shape button should read “CLEAR”. The rectangular shape button
should be visually appealing and its upper left corner should be aligned with the upper left
corner of cell F16.
4
IE 212: Computational Methods for Industrial Engineering
Summer 2015
Homework #4: Writing sub procedures
Tuesday, July 14th, 2015
Student Name:
Download