Chapter 22. Creating screen input

Screen input or data input is the ability to take input (from the keyboard in our case) then validate the input. If it’s OK accept it, if not throw it back out.

We have seen functions that test for certain conditions; for example the length of a string; whether a string is either numeric or character based. We will be using these functions amongst others in this chapter.

In this chapter we will cover:

  • validating input;

  • adding, deleting, amending and viewing records; and

  • working file update scripts.

This chapter may be a bit heavy going at the first read, so you may want to scan it first, then come back later. Validation can be fairly code-intensive, but to catch all possible errors, the code has to test for at least the most probable errors.

Let’s go through each task that is involved in creating a general file update system; namely adding, deleting, amending and viewing records. We will create a personal file update system. The records in our file called DBFILE will hold the following information.

Field Length Allow only Description
Staff number 10 Numeric Employee staff number
First name 20 Character Employee’s first name
Second name 20 Character Employee’s second name
Department Accounts Employee’s department
   IT 
   Services 
   Sales 
   Claims 

Each field is separated by a colon ‘:’. For example:

<Staff number>:<First name>:<Second name>:<Department>

Each task is presented as a complete script. Some small parts of the code are duplicated in a couple of the scripts presented. This is intentional, and the object of this chapter is to show you how a file update system is updated. When I first started scripting, one of the most frustrating things was the lack of clear documentation on putting a file update or database system together.

A live running script would have a menu connecting up the different tasks or module, or most probably a suite of functions contained in a file with one menu script. Each script contains the trap command; signals 2, 3 and 15 are ignored.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.42.193