Contents | Index | < Browse | Browse >


  DATABASE LISTVIEWS:
  ---------------------

A DataBase listview is not declared through a keyword such
as NUM or MULTI etc. - It is declared by loading a special
type of file. 

Example :  Run Gui   Source 

The file structure is simple :
- It must start with the header "GCDB"
- The next line must state the number of records in the file
- The next line is the number of Fields
- Then come the Field definitions (Name Size Type)
- Then come the data - i.e. the records - which are all the
  same size. Their size will be equal to the length of all the 
  fields added together. Records are separated with NewLine
  characters (Enter)

---------- Example file :
GCDB
1
3
%number 10 N
%item 30 S
%price 10 N
35        This is a dummy item          15000     
---------- end of file

The above file, when loaded into a listview, will be understood
as a DataBase file, and the listview will become a DataBase LV.

It will have 3 fields (or columns), %number, %item and %price
and 1 record (the last line shown).

If you thereafter load another (normal) text file, the LV will
become a normal LV again. And so on..

The LV's other atributes will remain the same - i.e. if it's a 
MULTI or a TXT etc listview, it will remain so..


   FIELDS :
   ---------------

Each line of a Database (or Dbase) LV is called a "record" and 
must be the same length as all the other lines.

Each record has fields which are just consecutive pieces of 
each record. You can think of them as columns. 

They are declared in the header. In the above example file, there 
will be 3 fields :

   Name     Length     Type               Start
   -------  --------   -----------        ------
   %number    10       N  (number)          0
   %item      30       S  (string)         10
   %price     10       N  (number)         40
   -------------------------------
   Record is  50 characters long

The 2nd field (%item), for example, starts at the 10th character
(i.e. where the previous field ends) and is 30 characters long. 
The next field starts where this one ends.

-  As you see field names *MUST* start with the % character.
   Unlike normal variables though, they are not case-sensitive.

-  The "Type" definition is :

   N   means a number
   S   means a string - i.e. any word, words, numbers..
   D   date (currently treated as if it were a string)

When their LV is CURRENT, fields can be used like variables :

lvuse gui 1                 ; use the above lv
lvgo #0                     ; goto the 1st record
%number = 15                ; set the "%number" field to 15
%price == $%number * 3      ; do a pointless calculation..
%item = "Another item"      ; change the %item field
say '$%price = $%itemn'    ; print out..

    should print out : 15 = Another item.

Each field has the value of whatever the CURRENT record of
it's listview contains.

So, if you added a lot of records to the above lv, you could, 
for example, do this :

lvuse gui 1
lvgo first                        ; use the lv & goto top
while $$lv.line > ''              ; do for all records
   total == $%number * $%price    ; calculate CURRENT record
   say '$%item costs $totaln'    ; print info
   lvgo next                      ; get next record
endwhile

It is important to understand that the %fields exist ONLY
when the listview in which they are defined is CURRENT.
If you LVUse another listview, then they will disappear and
the other listview's records (if any) will appear.


   COMMANDS and DBASE LVs
   -----------------------

There are some commands which behave differently if they are
given a dbase listview to deal with.

   LVADD     string  - the line added will be of "record" length
                     i.e. as long as all the lengths of all
                     the fields added together.

   LVINSERT  string  - again, a record length line will be added.

   LVPUT     string  - will Overwrite the current record, without
                     changing it's length.

   LVSORT     %Field - will sort the listview according to the
                     given field. Nice eh?

In general, Gui4Cli will help you in making sure that the record
lengths are kept the same. You can, however, circumvent that
and trash a database listview if you handle it carelessly, so
BEWARE!! - keep record lengths the same.


   DATABASE COMMANDS :
   ---------------------

There are a few new commands which are specifically for DBase LVs :                     

-  DBSUM  ALL|SELECTED|UNSELECTED %FieldName ResultVar

  will add the values of a certain field for all or the selected/
  unselected records and put them into a variable. 

-  RECSORT  %FieldName

  will sort the current record into the current listview according
  to the %field given.

... that's it for now...