Applications Programming --- Lab 5
Objective:
- Learn to develop a simple VBA program with conditions
References:
Problem Description
A new-age Taxi company let its riders have two choices
of calculting ride fare:
- the user can negotiate a fare with the driver before the ride
(Uber style). Or
- the fare is calculated based on the distance travelled and the idle
minutes during the ride (traditional Taxi style).
If a rider choose this style, the company charges $1.5 per kilometer
and $0.55 for each minute the taxi is not moving during the ride.
Your Tasks:
- Download the Lab 5's template workbook file:
lab5-input.xlsx.
- Open the template file you just downloaded and design and
implement a VBA program that calculate the taxi fare for
a user based on the user choice and trip information.
for the farmer.
- Your program first ask the user which style of fare calculation
he/she wants to use;
(Hint: your program can prompt the user to enter U for Uber style
and T for traditional style, and then read the user input.)
- If the user chooses Uber style, ask the user to enter
the negotiated fare amount.
- If the user chooses the traditional style, ask the user
to enter the following information:
- the distance travelled in kilo-meters of the ride, and
- the number of minutes the taxi was not moving (idling) during
the travel.
- Calculate the fare according to the information collected;
- Use a message box to show the fare;
- Save the trip information, user choice and fare information
to the appropriate cells in row 9 of the Excel file.
- Save your work to a Macro-enabled Excel file (with the extension name
.xlsm).
In order to make your program sufficiently robust, when your program
collect the data of pre-negotiated fare, distance travelled and idling
minutes, always
perform user input validation by first read in these numbers as
strings, then check whether these strings are numerical numbers
(using IsNumeric function). If they are numbers, then convert them
to floating point numbers (using CDbl function)
and test whether these numbers are positive ones.
If the user enters a non-numerical data or negative numbers
as pre-negotiated fare, distance and/or idling minutes,
using message box to display an appropriate error message
and then terminate your program right away.
When you develop your VBA program, you need to pay attention to
the following things:
- Did you use "Option Explicit" at the beginning of your program?
- Did you use named constants to represent any literal values?
- Did you give meaningful names to your variables and constants?
- Did you use appropriate messages when you show the calculation
result to the users?
- Did you remember to save data to Excel file in your program?
There is a weekly Assignment 5
following this lab.