Hands-On Exercise 3
For your next hands-on exercise, you will stop using public variables to hold the answers to the prompts. Instead, you'll use a list to hold the answers and pass the list as an argument to the methods. You will also add error checking to the prompts.
Write a method that use the pattern match operator to validate the Name. Up to now you've been entering names as “First Last”, but your code should now validate names as “Last,First”. The method should write an error message for invalid names.
Write a method that uses $Match to validate the Phone, with an error message for invalid phones.
Add a default area code to the Phone prompt, and a line to add this default to phone numbers without area codes.
Write a method that uses $ZDateH to validate the Date of Birth, and convert it to internal format. Make sure it's a date in the past (before today). The method should write an error message for invalid dates. The method should return the internal format version of the date of birth using an argument passed by reference.
Call the new validation methods from your prompts, repeating each prompt until there's a valid entry.
Change Main() so that Prompt() passes a variable answers by reference and Display() passes answers by value.
Change the signature of Prompt() so that it takes the answers argument by reference, and remove the Publiclist. Add a line at the end that uses $ListBuild to set answers so that it holds the Name, Phone, and the internal format of the Date of Birth.
Change the signature of Display() so that it takes the answers argument by value, and remove the Publiclist. Add a line at the beginning that uses $List or Set $ListBuild to retrieve the Name, Phone, and the internal format of the Date of Birth from answers. Use $ZDate to display the date, no matter how the user actually entered it, in one of the standard formats.
Save as ObjectScript.DataEntry3, compile, and test all three prompts with bad and good input.
For instructions, click below.