Grids Tutorial

From BR Wiki
Revision as of 15:32, 11 July 2013 by Laura (talk | contribs)
Jump to navigation Jump to search

Like lists, GRIDS are made of rows and columns and are created using INPUT FIELDS and PRINT FIELDS. However, with grids the user can change information within the cells. This is handy for updating files.

Just like lists, the data in grids can be sorted according to the column header that the user clicks on. And once again this changes the data's appearance but does not change its form in the file.

1. Grids also have a header row defined by headings, widths, and forms:

00250 PRINT FIELDS "2,2,GRID 10/36,headers": (Mat Headings$,Mat Widths,Mat Forms$)

2. Then information must be populated in the grid:

03020 PRINT FIELDS "2,2,GRID 10/36, =": (Mat Item$, Mat Color$, Mat Idnum)

Grids use the same primary and secondary flags as lists for population.

3. When handling user activities, grids can use the same read and selection types as lists, as seen in the charts above. Grids also have extra options that cannot be used in lists:

Read types for grids only:

Cnt Specify the number of cells specified (see selection types).
Sub Read the Cell Subscript Values.
Cell Read each cell specified.

There is one Selection Type valid for Grids only, which allows the user to edit values in the grid:

Chg All items changed since the last '=' populate or the last CHG retrieval of cell/row contents.

Reopen the program you've been working on in the chapter exercises (using the information from ORDERS.INT), save it under the name GRID1 and change all instances of LIST to GRID. (There are three in our program).

Then run the program. What differences do you see?

Now you can select one cell at a time instead of one row at a time, and make changes! Go ahead and try it!

Run it again.

Have your changes been saved? (No!?) Next we'll need to change the program to record what you've done. You will need to use the CHG selection type, record the rows with changes into a new array, and then rewrite the rows that were changed into the file. Try to do this alone without looking ahead first.

For help, see the program 1.5 part one, on the Solutions page.

Go ahead and run the sample program to try it now! Need more evidence? If you re-run the original program Samplist, will you find your new changes available for selection? (Yes!)

Next, what if you want to add an entire new entry? Remember the primary flags above? Edit your program to add a new record. And then to save the new entry in the file. See part 2 on the solutions page for help.


Next: Index and Sort facilities Tutorial Back: Table of Contents