演習 2 : 2 番目のデータ入力クラス
チュートリアル本編の演習の説明に戻るには、ここをクリックします。
-
VS Code - ObjectScript を使用して、ObjectScript.DataEntry1 の先頭行を ObjectScript.DataEntry2 に変更し、ObjectScript.DataEntry2 という名前で保存します。
-
プロンプトを含むように 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 } }
-
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 !, "========================================", ! } }
-
Prompt() の上に、ループを実行して他の 2 つのメソッドを呼び出すように Main() を記述します。
Class ObjectScript.DataEntry2 { /// Main loop section ClassMethod Main() { while ..Prompt() { do ..Display() } } // this is where the Prompt() method is }
-
[保存] ボタン、[コンパイル] ボタンをクリックします。
-
ターミナルを開始し、do ##class(ObjectScript.DataEntry2).Main() と入力してメソッドを実行します。