演習 2 : ストレージ・サブルーチンの追加
-
スタジオを開始し、myBASdatent ルーチンを開きます。終了したルーチンも、BASdatent2.BAS として SAMPLES ネームスペースで使用できます。
-
validPhone 関数に If 文を追加し、電話番号データがインデックス内に既に存在するかどうかを確認します。
public function validPhone(phone As %String) As %String 'validate a phone - just checks for 3 pieces using "-" and length 'returns 0 for an invalid phone and writes error message 'else returns unchanged phone with default area code added if (len(phone) = 8 and len(phone, "-") = 2) then phone = "617-" & phone ' add default area code end if if (len(phone) = 12 and len(phone, "-") = 3) then if exists( ^PersonI( "Phone", phone)) then print "Phone number in use" : println return 0 else return phone end if else print "###-###-#### or ###-####" : println return 0 end if end function
-
新規の store サブルーチンを追加します。
public sub store() ' store the data dim yn, id, rec, ln, fn input "Store? (y/n): ", yn ' see if user wants to store ' only go on if user says yes if ( yn <> "y" ) then println "...not stored." exit sub end if id = increment(^PersonD) ' generate a new id rec = name & "^" & phone & "^" & intdob ' concatenate data into a record ^PersonD( id ) = rec ' store the record ' break name for storage in index ln = piece(name, ",", 1) : fn = piece(name, ",", 2) ' the next three statements store data in subscripts ' because of the automatic sorting of subscripts, ' this has the effect of building 3 indices: name, phone, and DOB ^PersonI( "Name", ln, fn, id) = "" ' store the name ^PersonI( "Phone", phone) = id ' store the UNIQUE phone ^PersonI( "DOB", intdob, id) = "" ' store the DOB println "...stored" ' done end sub
-
何人かを格納し、管理ポータルでグローバルを表示します。