0% found this document useful (0 votes)
6 views

test-question-2020-vba-test

The document outlines the instructions for a VBA test in Quantitative Business Analysis at City University of Hong Kong. It details the tasks to be completed using specific Excel files, emphasizes academic integrity, and provides guidelines for coding style and submission procedures. The test involves programming tasks related to handling customer transaction data and user interactions within a form in Excel.

Uploaded by

詠芯謝
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

test-question-2020-vba-test

The document outlines the instructions for a VBA test in Quantitative Business Analysis at City University of Hong Kong. It details the tasks to be completed using specific Excel files, emphasizes academic integrity, and provides guidelines for coding style and submission procedures. The test involves programming tasks related to handling customer transaction data and user interactions within a form in Excel.

Uploaded by

詠芯謝
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

lOMoARcPSD|18632687

Test Question 2020 - VBA test

Quantitative Business Analysis with Visual Basic for Applications (City University of
Hong Kong)

Scan to open on Studocu

Studocu is not sponsored or endorsed by any college or university


Downloaded by gu gu ([email protected])
lOMoARcPSD|18632687

MS3111 QBA with VBA


Test
Instructions:
¥ Click on ‘Take the Quiz’ in ‘Test’ to start the test. The files TestQuestion_2020.pdf (the full
version of this file), Test_2020.xlsm, and Transactions.xlsx are then available for download. You
must use your downloaded files to complete the test.
¥ Change the name of Test_2020.xlsm to nnnnnnnn.xlsm, where nnnnnnnn is your EID (i.e., your
login name, not your student number). You must put your program code in nnnnnnnn.xlsm.
¥ You must not receive help in any form from another person nor copy the answers from any
source. Misconduct behaviour will be dealt with in accordance with the University’s
Academic Regulations.
¥ You must note the following when writing your code:
o Explicitly specify the utilized property of an object in your code. For example, you must
write TextBox1.Value for the Value property of TextBox1 in your code. Omission of
property specification will be considered an error.
o Declare variables at the module level only if it is necessary. Unless more than one sub
needs to access a variable's stored value, the variable must be declared within the sub
that determines the value of the varaible. If a variable is declared at module level but its
stored value is not accessed by multiple subs, it will be considered an error.
o Write your code so that the system will execute the code according to the task list's order.
For example, the code of Task 1a must be executed before that of Task 1b, and so forth.
Code that is not executed by the system in the designated order will be considered as an
error.
o Write your code in a good coding style. Good code style includes statements with proper
indentation, sufficient comment statements, meaningful variable names, properly
declared variables, and easily understood, etc. Up to 10 marks shall be deducted for a
poor coding style.
¥ The total marks of this test are 55.
¥ You must submit your nnnnnnnn.xlsm file via the link ‘Test’ in the Quizzes section of Canvas.
You may attempt the quiz multiple times while it is still available. Only the most recent
submission will be marked. You must stop your work at 12:00 pm and then submit your file
before 12:05 pm. The test link will be closed at 12:05 pm. Submission by other methods will
not be accepted.
¥ You should save your program file regularly during the test. You will not get extra time for
losing your work during the test for any reason. It is for your benefit to submit your
nnnnnnnn.xlsm file to Canvas regularly by retaking the quiz within the allowed time.
¥ You should keep your final submitted nnnnnnnn.xlsm file safe, and do not attempt to modify it
after submission. If it is necessary to recall your original copy of the file, the file may be
submitted to CSC for forensic analysis to assess whether it is created or modified after-the-fact.
¥ If Dr Yuen has anything to announce during the test, he will do it through the Announcements
of Canvas.
¥ If you have any query about the test during the test period, you may call Dr Yuen immediately
at the phone number +852 34428579 or send him an email ([email protected]). Dr Yuen
may not be able to respond to your email instantly.

Downloaded by gu gu ([email protected])
lOMoARcPSD|18632687

Workbooks and Worksheets Description


The workbook Transactions.xlsx contains information about customers in several worksheets.
Note the following:
¥ Assume the exact location and the name of Transactions.xlsx are unknown to you at design
time. You must not write the name and the path of the workbook in your program code. You
must not change its contents at design time or run time unless you are told to do so explicitly.
¥ Transactions.xlsx contains a worksheet with tab name “OrderList”.
¥ Transactions.xlsx contains other worksheets, but you do not know what they are at design
time, and you do not know which worksheet will be the active worksheet when the workbook
is opened at run time.

The worksheet “OrderList” contains the purchased records of the customers. Note the following:
¥ The position of “OrderList” in Transactions.xlsx is unknown to you at design time. It is not
necessary the active worksheet when Transactions.xlsx is opened.
¥ You may use the object name Worksheets("OrderList") in your program code.
¥ The column titles “Customer Identification”, “ Product Code”, and “Amount Purchased” are
always in cells A1, B1, and C1, respectively. You may make use of this information in your
program code.
¥ the worksheet will contain at least one row of records, and the first record will always start in
Row 2 of the worksheet. The records are not arranged in any order, and the same customer
identification number may appear more than once in the records. There is no empty row
between any two records. The exact number of records and the content of each record are
unknown to you at design time.

The Workbook Test_2020.xlsm contains the userform frmPurchases.


¥ You must not change the appearance of frmPurchases and the properties of the controls on
frmPurchases at design time or at run time unless you are told to do so explicitly.
¥ You may enter your code into the included subs as needed, but you must place your code at
the location as instructed. You must not modify the code that is already contained in these
subs.
¥ You must put all of your code into the code window of frmPurchases unless you are told to do
it differently.

Downloaded by gu gu ([email protected])
lOMoARcPSD|18632687

Tasks:
Write VBA code in nnnnnnnn.xlsm that does the following tasks sequentially:

1. Programmatically set to display the page “Open File” of the MultiPage control mpgReport
before frmPurchases is drawn to the screen at run time.

2. When the CommandButton btnOpenFile is clicked on, a system open file dialog box will appear
(the code is already provided in the related sub). Provide code for the following activities:
a. If the user clicks the “x” button or the “Cancel” button on the displayed open file dialog box:
i. Immediately display the message “Must select a workbook!” in a system message dialog
box.
ii. Then do nothing else except stopping the running sub, but do not end the application.
b. If the user selects a workbook from the displayed open file dialog box:
i. Immediately open the selected workbook. (You may assume the user will choose to open
Transactions.xlsx. No checking is required.)
ii. Then assign the newly opened workbook to an appropriate object variable so that other
subs can access the workbook within the same code window via the object variable.
c. Populate the Listbox control lstRecords on the page “Records” of mpgReport by the product
codes in the column “Product Code” of worksheet “OrderList” in Transactions.xlsx. Each
product code listed in lstRecords must be unique. No blank rows will be contained in
lstRecords when this is done. You may include the object name Worksheets("OrderList") in
your code.
d. Open a new workbook. Then assign the newly opened workbook to an appropriate object
variable so that other subs can access it within the same code window via the object
variable.
e. Activate the workbook nnnnnnnn.xlsm. You are not allowed to activate any other workbooks
from this task onward.
f. Show page “Records” of mpgReport.

3. User may select one or more items in lstRecords. Whenever the user has selected an item in
lstRecords:
a. Determine the number of items currently selected.
b. If the current number of selected items is four:
i. Immediately display this message “Not allowed to select more than three items. Select
again.” in a system message dialogue box.
ii. Deselect the last selected item in lstRecords.

4. When the CommandButton btnReport is clicked on:


a. Perform the following activities for each selected item in lstRecords in turn:
i. Add one new worksheet to the workbook created in Task 2d.
ii. Set the selected product code as the tab name of the newly added worksheet in Task 4a.
iii. Write only the values of the customer’s identification number and the amount purchased
of every transaction record of the selected product in “OrderList” into columns A and B of
the new worksheet. Starting from Row “1” of the new worksheet, put one transaction
record into 1 row. There must be no blank rows between two inserted records. You are
not allowed to write the product code values into the new worksheet at all during this
process. For example, if one of the selected items in lstRecords is ‘B12’, the new
worksheet for ‘B12’ should look like this:

Downloaded by gu gu ([email protected])
lOMoARcPSD|18632687

There is no need to adjust the column width


programmatically.

b. Enable page “Quit” of mpgReport.

5. When the CommandButton btnQuit on page “Quit” is clicked on:


a. Suppress Excel’s prompts and warning messages.
b. Save the new workbook as specified in Task 2d as ‘ReportTestA.xlsx’, and save it to the same
folder of Transaction.xlsx as specified by the user in Task 1bi.
c. Close the new workbook.
d. Close the workbook Transaction.xlsx opened in Task 2bi without saving. No confirmation
from the user is required.
e. Terminate the application.

- - The End - -

Steps to submit your nnnnnnnn.xlsm file to Canvas:


¥ Save and close nnnnnnnn.xlsm.
¥ Upload nnnnnnnn.xlsm via the Question 1 in the ‘Test’ link of Canvas. You may need to login to
Canvas again due to inactivity. Submit only nnnnnnnn.xlsm.
¥ Click on ‘Submit Quiz’ to complete the process. You should be able to view your ‘Attempt
History’ about the test.

Downloaded by gu gu ([email protected])

You might also like