@@ -4,92 +4,90 @@ Class ObjectScript.DataEntry3
4
4
/// Main loop section
5
5
ClassMethod Main ()
6
6
{
7
- While ..Prompt (.answers ) {
8
- Do ..Display (answers )
7
+ while ..Prompt (.answers ) {
8
+ do ..Display (answers )
9
9
}
10
10
}
11
11
12
12
/// prompt
13
13
ClassMethod Prompt (ByRef answers As %String ) As %Boolean
14
14
{
15
- Do {
16
- Read !, " Name: " , name
17
- Return :(name = " " ) 0 // user entered nothing so return FALSE, exit loop AND method
18
- }
19
- While '..ValidName (name )
15
+ do {
16
+ read !, " Name: " , name
17
+ return :(name = " " ) 0 // user entered nothing so return FALSE, exit loop AND method
18
+ } while '..ValidName (name )
20
19
21
- Do {
22
- Read !, " Phone (617): " , phone
23
- }
24
- While '..ValidPhone (.phone )
20
+ do {
21
+ read !, " Phone (617): " , phone
22
+ } while '..ValidPhone (.phone )
25
23
26
- Do {
27
- Read !, " DOB: " , dob
28
- }
29
- While '..ValidDOB (dob , .intdob )
30
- Set answers = $Listbuild (name , phone , intdob )
31
- Return 1 // return true
24
+ do {
25
+ read !, " DOB: " , dob
26
+ } while '..ValidDOB (dob , .intdob )
27
+ set answers = $listbuild (name , phone , intdob )
28
+ return 1 // return true
32
29
}
33
30
34
31
/// use pattern match to validate a name in "Last,First" format.
35
32
/// write error message if invalid
36
33
ClassMethod ValidName (name As %String ) As %Boolean
37
34
{
38
- If (name ?1 U .L1 " ," 1 U .L ) {
39
- Return 1 }
40
- Else {
41
- Write !," Last,First"
42
- Return 0
43
- }
35
+ if (name ?1 U .L1 " ," 1 U .L ) {
36
+ return 1
37
+ }
38
+ else {
39
+ write !," Last,First"
40
+ return 0
41
+ }
44
42
}
45
43
46
- /// use RegEx ($Match ) to validate a phone in "###-####" or "###-###-####" format.
44
+ /// use RegEx ($match ) to validate a phone in "###-####" or "###-###-####" format.
47
45
/// returns the converted phone by reference
48
46
/// write error message if invalid
49
47
ClassMethod ValidPhone (ByRef phone As %String ) As %Boolean
50
48
{
51
- If $Match (phone , " (\d{3}-)?\d{3}-\d{4}" ) {
52
- Set :($Match (phone , " \d{3}-\d{4}" )) phone = " 617-" _ phone // add default area code
53
- Return 1
49
+ if $match (phone , " (\d{3}-)?\d{3}-\d{4}" ) {
50
+ set :($match (phone , " \d{3}-\d{4}" )) phone = " 617-" _ phone // add default area code
51
+ return 1
54
52
}
55
- Else {
56
- Write !, " ###-###-#### or ###-####"
57
- Return 0
53
+ else {
54
+ write !, " ###-###-#### or ###-####"
55
+ return 0
58
56
}
59
57
}
60
58
61
- /// validate a date of birth using $ZDateh and $Horolog
59
+ /// validate a date of birth using $zdateh and $horolog
62
60
/// returns the internal form of the date of birth by reference
63
61
/// write error message if invalid
64
62
ClassMethod ValidDOB (date As %String , Output convdate As %Date ) As %Boolean
65
63
{
66
- Set convdate = $ZDateh (date , 5 ,,,,,,, -1 )
67
- If (convdate = -1 ) {
68
- Write !," Must be a valid past date"
69
- Return 0 // invalid date
64
+ set convdate = $zdateh (date , 5 ,,,,,,, -1 )
65
+ if (convdate = -1 ) {
66
+ write !," Must be a valid past date"
67
+ return 0 // invalid date
70
68
}
71
- ElseIf (convdate > $Piece ( $Horolog , " ," , 1 )) {
72
- Write !," Must be a valid past date"
73
- Return 0 // invalid because it's in the future
69
+ elseif (convdate > $piece ( $horolog , " ," , 1 )) {
70
+ write !," Must be a valid past date"
71
+ return 0 // invalid because it's in the future
74
72
}
75
- Else {
76
- Return 1 // valid date
73
+ else {
74
+ return 1 // valid date
77
75
}
78
76
}
79
77
80
78
/// display the data
81
79
ClassMethod Display (answers As %String )
82
80
{
83
- Set $Listbuild (name , phone , intdob ) = answers
81
+ set $listbuild (name , phone , intdob ) = answers
84
82
/* the line above is equivalent to
85
- Set name = $List (answers, 1),
86
- phone = $List (answers, 2),
87
- intdob = $List (answers, 3) */
88
- Write !!, " ========================================"
89
- Write !, " Name:" , ?20 , name
90
- Write !, " Phone:" , ?20 , phone
91
- Write !, " DOB:" , ?20 , $ZDate (intdob , 2 )
92
- Write !, " ========================================" , !
83
+ set name = $list (answers, 1),
84
+ phone = $list (answers, 2),
85
+ intdob = $list (answers, 3) */
86
+ write !!, " ========================================"
87
+ write !, " Name:" , ?20 , name
88
+ write !, " Phone:" , ?20 , phone
89
+ write !, " DOB:" , ?20 , $zdate (intdob , 2 )
90
+ write !, " ========================================" , !
93
91
}
94
92
95
93
}
0 commit comments