0% found this document useful (0 votes)
4 views4 pages

Assignment2_2024B

The assignment requires individual completion of tasks related to data analytics using Excel VBA, focusing on user forms for order processing at CityU Café. Students must adhere to strict guidelines regarding code modification, collaboration, and submission format, with specific tasks outlined for managing product orders and reports. Key tasks include setting properties for controls, processing orders, managing totals, and displaying accumulated sales in a report form.

Uploaded by

詠芯謝
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Assignment2_2024B

The assignment requires individual completion of tasks related to data analytics using Excel VBA, focusing on user forms for order processing at CityU Café. Students must adhere to strict guidelines regarding code modification, collaboration, and submission format, with specific tasks outlined for managing product orders and reports. Key tasks include setting properties for controls, processing orders, managing totals, and displaying accumulated sales in a report form.

Uploaded by

詠芯謝
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

MS3111 Data Analytics with Excel VBA

Assignment 2

Instructions:

• This assignment is not a team assignment. You are expected to complete the assignment by yourself.
Discussions between classmates are encouraged, but you must not cross the line between discussion
and plagiarism (such as sharing the answer in any way). Under no circumstances should you show
your code to other students. All students involved in identified collaboration works will receive 0
marks for this assignment and may be subject to further disciplinary penalties (such as failing this
course).
• Save the workbook containing your work as nnnnnnnn.xlsm where nnnnnnnn is your CityU Student
Number. You are reminded to save the workbook as an Excel Macro-Enabled Workbook. Submit your
Excel file via the designated link under the Assignments section in Canvas before 06:00 AM on 19
March 2025. Only the last submitted file will be marked if you submit your file more than once.
Submission by other methods will not be accepted.
• You must not change the appearance of the forms frmCafe and frmReport and the properties of any
controls on the forms at design time or runtime unless you are told explicitly to do so.
• You may enter your code into the included subs, but you must not change the code that is already
contained in these subs.
• All code must be processed sequentially according to the order imposed by the task list. For example,
Task 1ai must be executed before Task 1aii if both are in the same sub. The code not being executed in
the required task order will be considered an error.
• You must specify all utilised properties of Userform controls properly in your code. For example, the
Value property of TextBox1 must be specified as TextBox1.Value. Missing the property specification will
be considered an error.
• Unless the assigned value of a variable is needed again by any subs while the application is still running,
it must be declared inside the sub that uses the variable. If the value of a module-level variable is not to
be reused by more than one sub, it will be considered an error.
• You should provide statements only as required by the tasks. Redundant statements (including
irrelevant statements or statements not associated with the listed tasks) will be considered errors.
• Utilising codes not included in the course notes will not be accepted as correct answers, even though
they are not wrong.
• Marks will be deducted for the poor layout of the code. That includes non-properly named or declared
variables, poor flow of the program, lack of comment statements, low readability, etc.

Tasks:
The Userforms frmCafe and frmReport in Assignment2_2024BPartial.xlsm are designed to calculate the
amount due for individual orders at CityU Café and maintain a report for accumulated totals of each
product. Both Userforms will be loaded during the application's run time, but only form frmCafe will be
shown to the user by default. The form frmReport will only be displayed at the user’s request. For all
required tasks, you must not hard code any product name (such as “Espresso”, etc.), any product price
(such as “$25.0” or 25.0, etc.), and the current total number of available products (such as 4) in your
submitted code. Such information must be determined at run time with appropriate code. You are asked
to provide code for the following tasks.
Task 1: Before frmCafe is drawn to the screen at run time, set the following properties of SpinButton
control spnQuantity programmatically:
a) The maximum value to 20.
b) The SmallChange value to 1.

Task 2: The user will select one of the products in ListBox control lbxProducts for an order, one product at a
time. When any of the products in lbxProducts is selected, enable Frame control fmeQuantity. {Hint: Utilize
the Change or Click event of lbxProducts.}

Task 3: The user will use spnQuantity at run time to specify the quantity of the selected product. Display
the current value of spnQuantity programmatically in the label lblQuantity’s caption.

Task 4: The user will click the btnSelect button to process the selected product. The user will repeat this
process for each product in the same order. At each time when btnSelect is clicked:
a) Add the name of the selected product to the bottom of the first column of ListBox control lbxOrder.
b) Add the order amount for the selected product to the bottom of the second column of lbxOrder. Do
not include the $ symbol in the column; only show the first decimal when there is a nonzero decimal in
the order amount (such as 25 or 30.5). The order amount equals the product's price times the quantity
specified in spnQuantity.
c) Increment the lblTotalDue’s caption by the order amount computed in Task 4b. The caption must begin
with the $ symbol and always be in precisely one decimal place (such as $25.0 or $30.5).
d) De-select the selected product in lbxProducts.
e) Reset the current value of spnQuantity to 1.
f) Disable fmeQuantity.

{Hint: For example, form frmCafe looks like the following for an order before the btnNextOder is clicked:

After the order for one cappuccino, one expresso,


another two cappuccinos, and three long black, the
frmCafe looks like this:

}
Task 5: The user may select one or more products in ListBox lbxOrder and remove them from the current
order. When any items lbxOrder are selected:
a) Enable the CommandButton btnRemove programmatically.
b) Disable btnRemove programmatically if no item in lbxOrder has been selected. (This may happen when
all selected items in lbxOrder have been de-selected or all selected items have been removed.)
{Hint: The Change event of a ListBox control with Multiselection enabled will be triggered by selecting or
deselecting one or more items from the list. The Click event of the ListBox control will not be fired under
such circumstances.}

Task 6: When the btnRemove button is clicked, repeat the following for each selected item in lbxOrder:
a) Decrease the displayed total due amount in lblTotalDue’s caption by the due amount of the selected
item in lbxOrder.
b) De-select the item in lbxOrder.
c) Delete the item from lbxOrder. The revised list in lbxOrder must not contain any blank lines.

Task 7: The application will accumulate the sales amount of each product in each order. The accumulated
sales amount for each product will be displayed in the ListBox control lbxReport on form frmReport. When
the user clicks on the btnNextOrder button on frmCafe:
a) Repeat the following activities for each product listed in lbxOrder:
i. If the product is already listed in lbxReport, increment the accumulated total in the second column
of lbxReport by the product’s current order amount as displayed in lbxOrder. Do not include the $
symbol in the column; only show the first decimal when a nonzero decimal is in the order amount.
{Hint: To programmatically manipulate a control (say labelB) on a loaded UserForm (say frmB) from
the code module of another UserForm (say frmA), the frmB name must be included in the
respective control reference. For example, frmB.labelB.Caption="ABC" .}
ii. If the product is not listed in lbxReport, add the product’s name to the bottom of the first column of
lbxReport. Then add the current order amount of the product to the bottom of the second column
of lbxReport. Do not include the $ symbol in the column; only show the first decimal when a
nonzero decimal is in the order amount (such as 50 or 30.5).
iii. Increment lblAccSales’s caption on frmReport by the current product order amount. The caption
must begin with the $ symbol and always be in precisely one decimal place (for example, $80.0 or
$80.5).
{Hint: After completing the first and second orders, the form frmReport should look like the
following.

After the first order, which includes two espressos, and


one cappuccino, is processed (i.e., btnNextOrder is
clicked), frmReport looks like this:
Within the same running session of the application,
frmReport looks like this after the second order, which
includes one espresso and one latte, is processed:

}
b) Remove all products in lbxOrder.
c) Reset the lblTotalDue’s caption as “$0.0”.

Task 8: Add an ActiveX CommandButton control onto Sheet1 of nnnnnnnn.xlsm. Provide code for this
control so the form frmCafe will be shown when clicked.
-- The End --

You might also like