docs.intersystems.com
Home  /  Application Development: Core Topics  /  ObjectScript Tutorial  /  Exercise 2: Second Data Entry Class


ObjectScript Tutorial
Exercise 2: Second Data Entry Class
[Back]
InterSystems: The power behind what matters   
Search:  


Click here to return to the exercise description in the main part of the tutorial.
  1. Using Atelier, change the top line of ObjectScript.DataEntry1 to ObjectScript.DataEntry2, and save it as ObjectScript.DataEntry2.
  2. 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
    }
    }
  3. 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 !, "========================================", !
    }
    }
  4. 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
    }
  5. Click the Save and Compile buttons.
  6. Start Terminal, and run your method, by typing do ##class(ObjectScript.DataEntry2).Main().