Hands-On Exercise 1
For your first hands-on exercise, you'll make a copy of the data entry routine we've provided. Then, you're going to add some simple error checking and messages to the routine. It has the following specification:
Prompts for Name, Phone (US Style), and Date of Birth.
Shows the data entered, in this format:
Name: John Smith Phone: 555-1111 DOB: 1/23/45Copy code to clipboard
Loops until the user doesn't enter anything at the Name prompt.
Perform these steps:
Start a Terminal session, switch to the SAMPLES namespace, and use Do to run the routine (do main^BASdatent1()).
Using Studio, click File –> Open. Choose “Basic File” in the Files Of Type field. Double-click BASdatent1.BAS to open it and load it into your project.
Click File –> Save As, and save the routine as myBASdatent.BAS.
In the Project tab of the Workspace window, double-click the Routines folder, right-click BASdatent1.BAS and remove it—don't delete it—from your project.
Write two public functions that use Piece() to do basic validation on the Name and Phone, and write an error message for invalid data. Your code should validate names as “Last,First”.
Write a public formatName() function, that uses UCase() and LCase() functions to convert the last and first names into the proper format, no matter how the user enters the name. Call this function after name validation.
Add a default area code to the Phone prompt, and a line to your function that adds this default to phone numbers without area codes.
Write a public function that uses the DateConvert() and DateDiff() functions to validate the Date of Birth, and convert it to internal format. The function should write an error message for invalid dates, and for dates in the future (after today).
Call the new functions from your prompts.
Display the date, no matter how the user actually entered it, in the standard format (use DateConvert() again).
Click File –> Save, and then Build –> Compile to compile the routine.
Using the Terminal, Do your routine.
For instructions, click below.