Exercise 2: Second Data Entry Class
Click here to return to the exercise description in the main part of the tutorial.
-
Using VS Code - ObjectScript, change the top line of ObjectScript.DataEntry1 to ObjectScript.DataEntry2, and save it as ObjectScript.DataEntry2.
-
Write the Prompt() method so that it contains the prompts.
Class ObjectScript.DataEntry2 { /// prompt until user doesn't enter a name ClassMethod Prompt() as %Boolean [Publiclist = (name, phone, dob)] { read !, "Name: ", name return:(name = "") 0 // user entered nothing so return FALSE and exit method read !, "Phone: ", phone read !, "DOB: ", dob return 1 // return true } }
-
Below Prompt(), write the Display() method so that it contains the display code.
Class ObjectScript.DataEntry2 { // this is where the Prompt() method is /// display the data ClassMethod Display() [Publiclist = (name, phone, dob)] { write !!, "========================================" write !, "Name:", ?20, name write !, "Phone:", ?20, phone write !, "DOB:", ?20, dob write !, "========================================", ! } }
-
Above Prompt(), write the Main() to loop and call the other two methods.
Class ObjectScript.DataEntry2 { /// Main loop section ClassMethod Main() { while ..Prompt() { do ..Display() } } // this is where the Prompt() method is }
-
Click the Save and Compile buttons.
-
Start the Terminal, and run your method, by typing do ##class(ObjectScript.DataEntry2).Main().