Skip to main content

This documentation is for an older version of this product. See the latest version of this content.Opens in a new tab

演習 2 : 2 番目のデータ入力クラス

チュートリアル本編の演習の説明に戻るには、ここをクリックします。

  1. VS Code - ObjectScript を使用して、ObjectScript.DataEntry1 の先頭行を ObjectScript.DataEntry2 に変更し、ObjectScript.DataEntry2 という名前で保存します。

  2. プロンプトを含むように Prompt() メソッドを記述します。

    
    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. Prompt() の下に、表示コードを含むように Display() メソッドを記述します。

    
    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. Prompt() の上に、ループを実行して他の 2 つのメソッドを呼び出すように Main() を記述します。

    
    Class ObjectScript.DataEntry2
    {
    /// Main loop section
    ClassMethod Main()    
    {   
        while ..Prompt() {
            do ..Display()
        }
    }
    
    // this is where the Prompt() method is
    }
  5. [保存] ボタン、[コンパイル] ボタンをクリックします。

  6. ターミナルを開始し、do ##class(ObjectScript.DataEntry2).Main() と入力してメソッドを実行します。

FeedbackOpens in a new tab