Information Technology Reference
In-Depth Information
20. Arrays
In the previous chapter we talked about copy members for the date ro utine. Note
that we had six different error messages depending on what was wrong with the date in
question. Once we get through with the date check, assuming this is an online program,
we need to check for any error and if there is one, we need the statements,
if date-switch = 1
screen (24,20) “date not numeric”
end-if
if date-switch = 2
screen (24,20) “day out of range”
end-if
if date-switch = 3
screen (24,20) “month out of range”
end-if
if date-switch = 4
screen (24,20) “zero is invalid for the year”
end-if
if date-switch = 5
screen (24,20) “invalid day for February”
end-if
if date-switch = 6
screen (24,20) “that month has only 30 days”
end-if
We should use this for every date we check and we could easily make it a
procedure. What we would do is move the date to be checked to a very specific new date
field and then pass this date to the procedure. Once the routine is done, we would have a
value for the field
date-switch ,
which would tell us if the date was valid or why it wasn't, depending on one of the six
values resulting from bad data. This checking could be put into a copy member but we
have another option. We can put each message into an array, with the messages, date not
numeric corresponding to 1, the message, day out of range corresponding to 2 and so
forth. With this in mind we won't need to use the above if statements since we will just
reference the message corresponding to
date-switch ,
which is the variable we use for determining what error has to be displayed. The fields
that are necessary can be seen in these statements.
define message-array character (180) element t-element character (30)
occurs 6 times structure
field character (30) value “date not numeric”
Search WWH ::




Custom Search