!01-04-90 entry errors
! WRITE a program that will examine the month and date and reject the entry
! BECAUSE it is of the wrong format
!
! LET when$ = 01-04-90 ! the wrong format for date
! SELECT CASE expression ! expression is when$ so all tests must be string tests
! CASE test1,test2 ! testn true is an error of type n, otherwise no error
! FIRST block ! print error message 1 or 2 and go to statement after END SELECT
! CASE test3
! SECOND block
! CASE test4,test5,test6
! THIRD block
! CASE else
! ANOTHER block ! this means no errors occurred, so set noerror$="true"
! this will escape the error do loop and go on to finish the conversion
! of the date to January 4, 1990
! END SELECT
! ! all the error tests point here, so print "Error in date format, try again"
!Another approach is the if then else structure. If the date entered
!is incorrect, you want the noerror$ = "false" condition to remain and the
!user to be asked to make another entry. A series of if tests could be used
!to catch all errors one can imagine. Only when all are passed is the flag
!changed to true so the loop is escaped.
!
!IF logical expression 1 THEN (escape) ! exp1=mo$(target$,pattern$,position) = "0"
! first block of statements ! executed if logical expression is true (error1)
!print "The month should not begin with 01, 02, etc.", then escape to statement after
!the end if.
!
!ELSEIF logical expression 2 ! da$(target$,pattern$,position) = "0"
! second block of statements ! executed if logical expression is true (error2)
!print "The day should not begin with 0, as in 04"
!ELSEIF logical expression 3
! third block of statements ! error 3 etc.
!ELSE
! second block of statements ! this occurs only if none of the expressions
!e1, e2, e3 etc. are true (errors). Thus, print the date is correct, and set
!noerror$="true" so the loop can be escaped.
!END IF
DO while more data
LET noerror$ = "false"
READ when$
!LET when$ = "1-3-99"
IF when$[1:1]="0" then
PRINT "The month should not begin with '0'"
ELSE IF when$[pos(when$,"-")+1:pos(when$,"-")+1]="0" then
PRINT "The day should not begin with '0'"
ELSE
PRINT "The date is in correct format"
LET noerror$ = "true"
END IF
PRINT "noerror$ is ..."; noerror$
LOOP
DATA "01-11-11", "1-01-11", "1-11-11"
END
The month should not begin with '0'
noerror$ is ...false
The day should not begin with '0'
noerror$ is ...false
The date is in correct format
noerror$ is ...true
! now put this coding element into PP6.2