Skip to main content

Exercise 2: Second Data Entry Class

Click here to return to the exercise description in the main part of the tutorial.

  1. Using VS Code - ObjectScript, 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 the Terminal, and run your method, by typing do ##class(ObjectScript.DataEntry2).Main().

FeedbackOpens in a new tab