Messages and User Inputs
Exercise 5.01

Exercise 5.01

The aim of this exercise is to ask the user a series of questions using basic input boxes and present their responses in the form of message boxes.

Files Needed

You don't need any files for this exercise.

Instructions

  1. Create a new workbook, insert a module and begin a new subroutine.
  2. Write code to display an input box which asks the user to enter their name and capture the result in a variable.
Basic inputbox

You can use either a VBA or an Excel input box for this example.

 
  1. Add code to display a message and exit the procedure if the user doesn't enter a name or clicks Cancel.
Error message

Your error message could resemble this one.

 
  1. Add code to display a second input box which asks the user to enter their date of birth.  Capture the result in a String variable.
Date of birth input

You could display today's date in a particular format to help the user enter a valid date.

 
  1. Add code to check that the user has entered a valid date.  If so, assign the value to a Date variable.  If not, display a message to the user and exit the procedure.
Date error message

Your error message could resemble this one.

 
  1. Add code to display a message box which summarises the user's input and asks if they would like to proceed.  Capture the result in a variable.
Summary message

Your summary message could resemble this one.

 
  1. Test which button the user clicked.  If the user clicks Yes, display a message which welcomes them to the application.
Welcome message

What the application does is anyone's guess.

 
  1. Add a different message if the user clicks No.
Bye message

Your message can be ruder than this if you like.

 

Answer Files

You can click here to download a file containing an example answer.

This page has 0 threads Add post