{$Debug}
Module AlphaLine;
(*
(
(	FILENAME:	ALineMod.Pas
(				Handles data collection for preparing a ALine Chart
(
(	CONTENTS:	GetALineData
(				SaveALineData
(				ALine_Chart
(
(	REVISION HISTORY
(
(	VERSION	DATE		BY	DESCRIPTION
(					
(
(	1.3.1	060486	CB	PrevNext function keys did not set the
(							variable iyValues to 1.
(	1.3		022586	CB	Increased size of LineNameType to
(							be compatible with the input form
(	1.2		021786	CB	Allow retries in OpenDataFile
(	1.1		011086	CB	Fixed CodeS
(	1.0		120185	CB	First release
(
(
*)

CONST 
   ALineCode    =  3;
   Cancel       =  7;
   CodeS        =  211;
   Code_s       =  243;
   ColorFmt     =  '[sys]<sys>ColorLine.Fm';
   DownArrow    =  11;
   DType        =  'Character.';
   F1           =  21;
   F3           =  23;
   F4           =  24;
   F5           =  25;
   F6           =  26;
   F8           =  29;
   F9           =  30;
   F10          =  31;
   Finish       =  4;
   Fmt          =  'ChgFmt';
   Go           =  27;
   ModeRead     =  ReType(WORD,'mr');
   ModeWrite    =  ReType(WORD,'mw');
   MonoFmt      =  '[sys]<sys>Line.Fm';
   NextPage     =  12;
   OverType     =  7;
   PrevPage     =  5;
   Saving       =  'Saving...';
   SaveCmplt    =  'Save Complete';
   UpArrow      =  1;
   WaitMsg      =  'Please WAIT.....';
   MaxLines     =  5;

TYPE 
   LineNameType =  ARRAY[1..MaxLines] OF LSTRING(35);
   LSFileSpec   =  LSTRING(50);
   Pointer      =  ADS OF WORD;
   xValueType   =  ARRAY[1..12] OF LSTRING(20);
   yValueType   =  ARRAY[1..MaxLines,1..12] OF Real;

VAR [EXTERN]
   AlphaLineForm  :  WORD;

VAR 
   ByteRet   :  BYTE;
   cbRead    :  WORD;
   cLines    :  WORD;
   cCoords   :  WORD;
   ChartType :  WORD;
   DataRet   :  LSFileSpec;
   fDone     :  BOOLEAN;
   fGraph    :  BOOLEAN;
   ExitState :  RECORD
                   ich[0]       :  WORD;
                   ch[2]        :  WORD;
                   fAutoExit[4] :  BOOLEAN;
                   fModified[6] :  WORD;
                   fEmpty[8]    :  WORD;
                   Reserved[10] :  ARRAY[1..6] OF BYTE;
                END;
   FldName   :  ARRAY[1..21] OF LSTRING(10);
   FmFile    :  LSFileSpec;
   Hdr       :  ARRAY[1..8] OF WORD;
   FormColumn:  Integer;
   FormRow   :  Integer;
   InitState :  ARRAY[1..4] OF WORD;
   I,J       :  Integer;
   iNames    :  Integer;
   ixValues  :  Integer;
   iyValues  :  Integer;
   LineTitle :  LSFileSpec;
   LineName  :  LineNameType;
   Ok        :  BOOLEAN;
   PicFile   :  LSFileSpec;
   Values    :  LSTRING(10);
   xLabel    :  LSTRING(32);
   xValue    :  xValueType;
   yLabel    :  LSTRING(32);
   yValue    :  yValueType;

   VALUE
   FldName[1] := 'LineTitle';
   FldName[2] := 'xLabel';
   FldName[3] := 'yLabel';
   FldName[4] := 'cLines';
   FldName[5] := 'cCoords';
   FldName[6] := 'LineData1';
   FldName[7] := 'LineData2';
   FldName[8] := 'LineData3';
   FldName[9] := 'LineData4';
   FldName[10] := 'LineData5';
   FldName[11] := 'LineData6';
   FldName[12] := 'LineData7';
   FldName[13] := 'LineData8';
   FldName[14] := 'LineData9';
   FldName[15] := 'LineData10';
   FldName[16] := 'LineData11';
   FldName[17] := 'LineData12';
   FldName[18] := 'Line';
   FldName[19] := 'xValue';
   FldName[20] := 'yValue';
   FldName[21] := 'Format';

{$Include:'Forms.Edf'}
{$Include:'Main.Edf'}
{$Include:'MiscMod.Edf'}

{
 Read the data file and load the data 
 into the appropriate variables.      
}

PROCEDURE GetALineData(VARS DataFile : LSFileSpec);

VAR 
   sbLegend  :  WORD;

BEGIN
   CheckErc(OpenDataFile(DataFile,ModeRead,False));
   CheckErc(ReadDataFile(ADS ChartType,2,ADS cbRead));
   CheckErc(ReadDataFile(ADS Hdr[1], 16,ADS cbRead));
   CheckErc(ReadDataFile(ADS cLines,2,ADS cbRead));
   CheckErc(ReadDataFile(ADS cCoords,2,ADS cbRead));
   FOR I := 1 TO Ord(cLines) DO
      BEGIN
         FOR J := 1 TO Ord(cCoords) DO
            CheckErc(ReadDataFile(ADS yValue[I,J],4,ADS cbRead));
      END;
   FOR I := 1 TO Ord(cCoords) DO
      BEGIN
         CheckErc(ReadDataFile(ADS sbLegend,2,ADS cbread));
         CheckErc(ReadDataFile(ADS xValue[I,1],sbLegend,ADS cbRead));
         xValue[I].Len := sbLegend;
         IF Odd(sbLegend)
            THEN CheckErc(Read_A_Byte(ADS ByteRet));
      END;

   CheckErc(Read_A_Byte(ADS ByteRet));
   CheckErc(ReadDataFile(ADS PicFile[1],Wrd(ByteRet),ADS cbread));
   PicFile.Len := Wrd(ByteRet);

   CheckErc(Read_A_Byte(ADS ByteRet));
   CheckErc(ReadDataFile(ADS FmFile[1],Wrd(ByteRet),ADS cbread));
   FmFile.Len := Wrd(ByteRet);

   CheckErc(Read_A_Byte(ADS ByteRet));
   CheckErc(ReadDataFile(ADS DataFile[1],Wrd(ByteRet),ADS cbread));
   DataFile.Len := Wrd(ByteRet);

   CheckErc(Read_A_Byte(ADS ByteRet));
   CheckErc(ReadDataFile(ADS LineTitle[1],Wrd(ByteRet),ADS cbread));
   LineTitle.Len := Wrd(ByteRet);

   CheckErc(Read_A_Byte(ADS ByteRet));
   CheckErc(ReadDataFile(ADS xLabel[1],Wrd(ByteRet),ADS cbread));
   xLabel.Len := Wrd(ByteRet);

   CheckErc(Read_A_Byte(ADS ByteRet));
   CheckErc(ReadDataFile(ADS yLabel[1],Wrd(ByteRet),ADS cbread));
   yLabel.Len := Wrd(ByteRet);

   FOR I := 1 TO Ord(cLines) DO
      BEGIN
         CheckErc(Read_A_Byte(ADS ByteRet));
         CheckErc(ReadDataFile(ADS LineName[I,1],Wrd(ByteRet),ADS cbread));
         LineName[I,0] := Chr(ByteRet);
      END;
   CloseDataFile;
END;

{
 Save data entered for this pie chart 
}

PROCEDURE SaveALineData(VARS DataFile : LSFileSpec);

CONST 
   Filler    =  0;

BEGIN
   IF fGraph
      THEN
(**)
(*     If fGraph then check to see if file already exists    *)
(**)
         REPEAT
            cbRead := ULCMPB(ADS DataFile[Ord(DataFile.len3)], ADS '.dat',4);
            IF cbRead <> FFFF
               THEN ConCat(DataFile, '.Dat');
            Movesl(ADS DataFile[1],ADS PicFile[1],DataFile.Len4);
            PicFile.Len := DataFile.Len4;
         UNTIL OverWriteOk(DataFile)
      ELSE
         BEGIN
(**)
(* Used CODES, do not check for data file go ahead and save *)
(**)
            cbRead := ULCMPB(ADS DataFile[Ord(DataFile.len3)], ADS '.dat',4);
            IF cbRead <> FFFF
               THEN ConCat(DataFile, '.Dat');
            Movesl(ADS DataFile[1],ADS PicFile[1],DataFile.Len4);
            PicFile.Len := DataFile.Len4;
         END;

   CheckErc(OpenDataFile(DataFile,ModeWrite,fGraph));

(**)
(* Write BGP data file *)
(**)
   WriteDataFile(ADS ALineCode,2);
   FOR I := 1 TO 8 DO
      Hdr[I] := FFFF;
   WriteDataFile(ADS Hdr[1],16);
   WriteDataFile(ADS cLines,2);
   WriteDataFile(ADS cCoords,2);
   FOR I := 1 TO Ord(cLines) DO
      BEGIN
         FOR J := 1 TO Ord(cCoords) DO
            WriteDataFile(ADS yValue[I,J],4);
      END;
   FOR I := 1 TO Ord(cCoords) DO
      BEGIN
         J := Ord(xValue[I].Len);
         WriteDataFile(ADS J, 2);
         WriteDataFile(ADS xValue[I,1],xValue[I].Len);
         IF Odd(J)
            THEN WriteDataFile(ADS Filler,1);
      END;

(**)
(* Append parameters passed to BGP via memory (VLPB) *)
(* to the end of the data file. This is done so that *)
(* all data for a given graph is located in one file *)
(* and can be easily recalled for Editing.           *)
(**)
   IF fGraph
      THEN ParamInit(2048,7);

   IF fGraph
      THEN ParamSetSimple(1,PicFile);
   WriteDataFile(ADS PicFile[0], PicFile.len+1);

   IF fGraph
      THEN ParamSetSimple(2,FmFile);
   WriteDataFile(ADS FmFile[0], FmFile.len+1);

   IF fGraph
      THEN ParamSetSimple(3,DataFile);
   WriteDataFile(ADS DataFile[0], DataFile.len+1);

   IF fGraph
      THEN ParamSetSimple(4,LineTitle);
   WriteDataFile(ADS LineTitle[0], LineTitle.len+1);

   IF fGraph
      THEN ParamSetSimple(5,xLabel);
   WriteDataFile(ADS xLabel[0], xLabel.len+1);

   IF fGraph
      THEN ParamSetSimple(6,yLabel);
   WriteDataFile(ADS yLabel[0], yLabel.len+1);

   IF fGraph
      THEN ParamListStart(7);
   FOR I := 1 TO Ord(cLines) DO
      BEGIN
         IF fGraph
            THEN ParamSetNextInList(LineName[I]);
         WriteDataFile(ADS LineName[I].Len,LineName[I].Len+1);
      END;

   CloseDataFile;
END;

{
 1) Collects all the data from the ALPHALINEFORM necessary to      
    graph a Line chart.                                            
 2) Chains to BGP.Run.                                             
                                                                   
 fEdit will be TRUE if the Edit Function key has been pressed or   
 all form fields have been accessed. DataSpec will then contain    
 the file spec of the data file.                                   
                                                                   
 Fields on the form are accessed by:                               
        setting FormColumn >  for the COLUMN the field is in   
        setting FormRow >  for the ROW the field is in      
                                                                   
             FormColumn = 1  FormColumn = 2  FormColumn = 3        
                         
 FormRow = 1 Title                                                 
           2 X Axis Name                                           
           3 Y Axis Name                                           
           4  of Lines                                            
           5  of Data Points per Line                             
           6 LineName[1]     XLabel[1]       YVal[1]               
           7 LineName[2]     XLabel[2]       YVal[2]               
           8 LineName[3]     XLabel[3]       YVal[3]               
           9 LineName[4]     XLabel[4]       YVal[4]               
          10 LineName[5]     XLabel[5]       YVal[5]               
          11                 XLabel[6]       YVal[6]               
          12                 XLabel[7]       YVal[7]               
          13                 XLabel[8]       YVal[8]               
          14                 XLabel[9]       YVal[9]               
          15                 XLabel[10]      YVal[10]              
          16                 XLabel[11]      YVal[11]              
          17                 XLabel[12]      YVal[12]              
                                                                   
}

PROCEDURE AlphaLine_Chart(fEdit  : BOOLEAN;
                          DataSpec : LSFileSpec);

BEGIN
   InitState[1] := 0;
   cLines  := 0;
   cCoords := 0;
   fDone := False;
   fGraph := False;
   FormRow := 1;
   FormColumn := 1;
   FOR I := 1 TO 5 DO
      FOR J := 1 TO 12 DO
         yValue[I,J] := 0;

   DisplayFKeys;
   DisplayFunctionKey(10,'Return',0);
   CheckErc(DisplayForm(ADS AlphaLineForm, 0, 255,255));

   IF fEdit
      THEN
         BEGIN
(**)
(* Go read the data file and display the data into *)
(* the form.                                       *)
(**)
            GetALineData(DataSpec);
            Write_the_FieldC(ADS AlphaLineForm, FldName[1], 0,
                             ADS LineTitle[1], LineTitle.Len);
            Write_the_FieldC(ADS AlphaLineForm, FldName[2], 0,
                             ADS xLabel[1], xLabel.Len);
            Write_the_FieldC(ADS AlphaLineForm, FldName[3], 0,
                             ADS yLabel[1], yLabel.Len);
            Write_the_FieldB(ADS AlphaLineForm, FldName[4], 0, ADS cLines);
            Write_the_FieldB(ADS AlphaLineForm, FldName[5], 0, ADS cCoords);
            FOR I := 1 TO Ord(cLines) DO
               BEGIN
                  Write_the_FieldC(ADS AlphaLineForm, FldName[I+5], 1,
                                   ADS LineName[I,1], LineName[I].Len);
               END;
            FOR I := 1 TO Ord(cCoords) DO
               BEGIN
                  Write_the_FieldC(ADS AlphaLineForm, FldName[I+5], 2,
                                   ADS xValue[I,1], xValue[I].Len);
                  Ok := Encode(Values,yValue[1,I]:10:2);
                  Write_the_FieldC(ADS AlphaLineForm, FldName[I+5], 3,
                                   ADS Values[1], Values.Len);
               END;
            Write_the_FieldC(ADS AlphaLineForm, FldName[21], 0, ADS FmFile[1],
                             FmFile.Len);
         END
      ELSE
         BEGIN
(**)
(* Set up the default Format file to be used to    *)
(* create the graph and display it to the form.    *)
(**)
            IF Color_Hdw
               THEN FmFile := ColorFmt ELSE FmFile := MonoFmt;
            Write_the_FieldC(ADS AlphaLineForm, FldName[21], 0, ADS FmFile[1],
                             FmFile.Len);
         END;

   WHILE NOT(fDone) DO
      BEGIN
         IF fEdit OR ELSE (cCoords > 0)
            THEN
               BEGIN
                  CheckErc(SetKbdLed(OverType,True));
                  DisplayFunctionKey(1,'Graph',4);
                  DisplayFunctionKey(3,Fmt,5);
                  DisplayFunctionKey(4,'Names',0);
                  DisplayFunctionKey(5,'XLabel',0);
                  DisplayFunctionKey(6,'YValue',0);
                  DisplayFunctionKey(8,Null,5);
                  DisplayFunctionKey(9,Null,5);
               END
            ELSE
               BEGIN
                  CheckErc(SetKbdLed(OverType,False));
                  DisplayFunctionKey(1,'Graph',0);
                  DisplayFunctionKey(3,Fmt,5);
                  DisplayFunctionKey(4,Null,0);
                  DisplayFunctionKey(5,Null,0);
                  DisplayFunctionKey(6,Null,0);
                  DisplayFunctionKey(8,Null,5);
                  DisplayFunctionKey(9,Null,5);
               END;

         CASE FormColumn OF
(**)
(* If the FormRow is > 5 then the Title, XAxis   *)
(* name, YAxix name, Number of Lines and number  *)
(* of Data Points per Line have been entered.    *)
(*                                               *)
(*    FormColumn = 1 is the LineName column.     *)
(*    FormColumn = 2 is the X Label column.      *)
(*    FormColumn = 3 is the Y Value column.      *)
(*                                               *)
(* This Case statement writes the number of the  *)
(* LineName, X Label or the Y Value into the     *)
(* form, that is currentlybeing input.           *)
(**)
            1 :
                 BEGIN
                    IF FormRow > 5
                       THEN
                          BEGIN
                             DisplayFunctionKey(4,'Names',0);
                             DisplayFunctionKey(5,'XLabel',0);
                             DisplayFunctionKey(6,'YValue',0);
                             CheckErc(DefaultField(ADS AlphaLineForm, ADS FldName[20,1],
                                      FldName[20].Len, 3));
                             CheckErc(DefaultField(ADS AlphaLineForm, ADS FldName[19,1],
                                      FldName[19].Len, 2));
                             Write_the_FieldB(ADS AlphaLineForm, FldName[18], 1,
                                              ADS iNames);
                             FOR I:=1 TO 12 DO
                                CheckErc(DefaultField(ADS AlphaLineForm,
                                         ADS FldName[I+5,1], FldName[I+5].Len, 3));
                             FOR I := 1 TO Ord(cCoords) DO
                                BEGIN
                                   Ok := Encode(Values,yValue[iNames,I]:10:2);
                                   IF yValue[iNames,I] <> 0
                                      THEN Write_the_FieldC(ADS AlphaLineForm, FldName[I+5],
                                                            3, ADS Values[1], Values.Len)
                                END
                          END
                 END;
            2 :
                 BEGIN
                    DisplayFunctionKey(4,'Names',0);
                    DisplayFunctionKey(5,'XLabel',0);
                    DisplayFunctionKey(6,'YValue',0);
                    DisplayFunctionKey(8,Null,5);
                    DisplayFunctionKey(9,Null,5);
                    CheckErc(SetFieldAttrs(ADS AlphaLineForm,
                             ADS FldName[iNames+5,1],
                             FldName[iNames+5].Len, 1,0));
                    Write_the_FieldB(ADS AlphaLineForm, FldName[19], 2,
                                     ADS ixValues);
                    CheckErc(DefaultField(ADS AlphaLineForm, ADS FldName[18,1],
                             FldName[18].Len, 1));
                    CheckErc(DefaultField(ADS AlphaLineForm, ADS FldName[20,1],
                             FldName[20].Len, 3))
                 END;
            3 :
                 BEGIN
                    DisplayFunctionKey(8,' Prev',4);
                    DisplayFunctionKey(9,' Next',4);
                    Write_the_FieldB(ADS AlphaLineForm, FldName[20], 1,
                                     ADS iyValues);
                    CheckErc(DefaultField(ADS AlphaLineForm, ADS FldName[18,1],
                             FldName[18].Len, 1));
                    CheckErc(DefaultField(ADS AlphaLineForm, ADS FldName[19,1],
                             FldName[19].Len, 2));
                    IF FormRow =5
                       THEN
                          BEGIN
                             CheckErc(SetFieldAttrs(ADS AlphaLineForm,
                                      ADS FldName[iNames+5,1],
                                      FldName[iNames+5].Len, 1,0));
                             DisplayFunctionKey(8,Null,5);
                             DisplayFunctionKey(9,Null,5)
                          END;
                    IF FormRow > 5
                       THEN CheckErc(SetFieldAttrs(ADS AlphaLineForm,
                                     ADS FldName[iNames+5,1],
                                     FldName[iNames+5].Len, 1,5));
                    IF FormRow = 6
                       THEN
                          BEGIN
                             FOR I := 1 TO 12 DO
                                CheckErc(DefaultField(ADS AlphaLineForm,
                                         ADS FldName[I+5,1], FldName[I+5].Len, 3));
                             FOR I := 1 TO Ord(cCoords) DO
                                BEGIN
                                   Ok := Encode(Values,yValue[iNames,I]:10:2);
                                   IF (yValue[iNames,I] <> 0) OR ELSE fEdit
                                      THEN Write_the_FieldC(ADS AlphaLineForm, FldName[I+5],
                                                            3, ADS Values[1], Values.Len)
                                END
                          END
                 END;
         OTHERWISE ;
         END;{case of FormColumn}

         Ok := FALSE;
         WHILE NOT(Ok) DO
            BEGIN
(**)
(* Ok will be set to TRUE if the data entered for *)
(* the form field is appropriate for that field.  *)
(* Data read from the field in the form is        *)
(* returned in the LString DataRet.               *)
(**)
               Read_The_FieldC(ADS AlphaLineForm, FldName[FormRow], Wrd(FormColumn), DataRet, Upper(DataRet), ADS ExitState);
               WriteStatusLine(ADS AlphaLineForm, Null, 0, False);

               CASE FormRow OF
(**)
(* Based on which Row and Column is active on  *)
(* the form this case statement knows what data*)
(* is being input and does the appropriate     *)
(* checks and places the entered data in the   *)
(* appropriate variable.                       *)
(**)
                  1 :
                       BEGIN
                          LineTitle := DataRet;
                          RemoveBlanks(LineTitle,DataSpec);
                          IF DataSpec.Len = 0
                             THEN Ok := False
                             ELSE [Ok := True;
                          FormColumn := 1;
                          iNames := 1;
                          ixValues := 1;
                          iyValues := 1];
                          CASE ExitState.ch OF
                             F10, Finish, Cancel :  Ok := True;
                          OTHERWISE ;
                          END;
                          IF NOT(OK)
                             THEN
                                BEGIN
                                   Beep;
                                   WriteStatusLine(ADS AlphaLineForm, 'An entry is required', 0,False)
                                END
                       END;
                  2 :
                       BEGIN
                          xLabel := DataRet;
                          FormColumn := 1;
                          Ok := True
                       END;
                  3 :
                       BEGIN
                          yLabel := DataRet;
                          FormColumn := 1;
                          Ok := True
                       END;
                  4 :
                       BEGIN
                          RemoveBlanks(DataRet,DataRet);
                          FormColumn := 1;
                          Ok := Decode(DataRet,cLines);
                          IF (cLines <= 0) OR (cLines > MaxLines)
                             THEN Ok := False;
                          CASE ExitState.ch OF
                             F10, Finish, Cancel, UpArrow :  Ok := True;
                          OTHERWISE ;
                          END;
                          IF NOT(OK)
                             THEN
                                BEGIN
                                   Beep;
                                   WriteStatusLine(ADS AlphaLineForm, 'Valid entries are 1  5.', 0,False)
                                END
                       END;
                  5 :
                       BEGIN
                          RemoveBlanks(DataRet,DataRet);
                          Ok := Decode(DataRet,cCoords);
                          IF (cCoords <= 0) OR (cCoords > 12)
                             THEN Ok := False;
                          CASE ExitState.ch OF
                             F10, Finish, Cancel, UpArrow :  Ok := True;
                          OTHERWISE ;
                          END;
                          IF NOT(OK)
                             THEN
                                BEGIN
                                   Beep;
                                   WriteStatusLine(ADS AlphaLineForm, 'Valid entries are 1  12.', 0,False)
                                END
                       END;
               OTHERWISE
                  BEGIN
                     CASE FormColumn OF
                        1 :
                             BEGIN
                                LineName[iNames] := DataRet;
                                Ok := True
                             END;
                        2 :
                             BEGIN
                                xValue[ixValues] := DataRet;
                                Ok := True
                             END;
                        3 :
                             BEGIN
                                RemoveBlanks(DataRet,DataRet);
                                Ok := Decode(DataRet,yValue[iNames,iyValues]);
                                CASE ExitState.ch OF
                                   F10, Finish, Cancel, UpArrow :  Ok := True;
                                OTHERWISE ;
                                END;
                                IF NOT(OK)
                                   THEN
                                      BEGIN
                                         Beep;
                                         WriteStatusLine(ADS AlphaLineForm, 'A Number is required', 0,False)
                                      END
                             END;
                     OTHERWISE ;
                     END{Case of FormColumn}
                  END;
               END;{Case of FormRow}
            END; {While Not(Ok)}

         CASE ExitState.ch OF
(**)
(* This case statement checks the value of *)
(* the keyboard key used to terminate the  *)
(* current form field.                     *)
(**)
            CodeS,
            Code_s   :  IF DataSpec.Len <> 0
                           THEN
                              [WriteStatusLine(ADS AlphaLineForm, Saving, 0, False);
            SaveALineData(DataSpec);
            WriteStatusLine(ADS AlphaLineForm, SaveCmplt, 0, False)];
            F1,Go    :  IF fEdit
                           THEN
                              BEGIN
                                 fDone := TRUE;
                                 fGraph := TRUE
                              END;
            F10      :
                        BEGIN
                           fDone := True;
                           fGraph := FALSE
                        END;
            Finish   :  ConfirmFinish;
            Cancel   :  WriteStatusLine(ADS AlphaLineForm, Null, 0, False);
            F3       :  Read_The_FieldC(ADS AlphaLineForm, FldName[21], 0, FmFile,
                                        Upper(FmFile), ADS ExitState);
            F4       :  IF fEdit OR (cCoords > 0)
                           THEN [FormColumn := 1;
            FormRow := iNames+5];
            F5       :  IF fEdit OR (cCoords > 0)
                           THEN [FormColumn := 2;
            FormRow := ixValues+5];
            F6       :  IF fEdit OR (cCoords > 0)
                           THEN [FormColumn := 3;
            FormRow := iyValues+5];
            F8,PrevPage :  IF (FormRow > 5) AND
                              THEN (FormColumn = 3) THEN
                                                       BEGIN
                                                          CheckErc(SetFieldAttrs(ADS AlphaLineForm, ADS FldName[iNames+5,1],
                                                                                 FldName[iNames+5].Len, 1, 0));
                                                          FormRow := 6;
                                                          iyValues :=1;
                                                          IF iNames <> 1
                                                             THEN iNames := iNames 1
                                                       END;
            F9,NextPage :  IF (FormRow > 5) AND
                              THEN (FormColumn = 3) THEN
                                                       BEGIN
                                                          CheckErc(SetFieldAttrs(ADS AlphaLineForm, ADS FldName[iNames+5,1],
                                                                                 FldName[iNames+5].Len, 1,0));
                                                          FormRow := 6;
                                                          iyValues :=1;
                                                          IF iNames <> Ord(cLines)
                                                             THEN iNames := iNames +1
                                                       END;
            UpArrow  :  IF FormRow = 1
                           THEN  DO nothing
                           ELSE
                              BEGIN
                                 FormRow := FormRow 1;
                                 IF FormRow > 5
                                    THEN
                                       BEGIN
                                          CASE FormColumn OF
                                             1 :  iNames := FormRow  5;
                                             2 :  ixValues := FormRow  5;
                                             3 :  iyValues := FormRow  5;
                                          OTHERWISE ;
                                          END;
                                       END
                              END;
            DownArrow:
                        BEGIN
                           CASE FormRow OF
                              1 :  FormRow := 2;
                              2 :  FormRow := 3;
                              3 :  FormRow := 4;
                              4 :  FormRow := 5;
                              5 :  FormRow := 6;
                              6..17 :
                                       BEGIN
                                          CASE FormColumn OF
                                             1 :  IF iNames = Ord(cLines)
                                                     THEN
                                                        BEGIN
                                                           iNames := 1;
                                                           FormRow := 6
                                                        END
                                                     ELSE
                                                        BEGIN
                                                           iNames := iNames + 1;
                                                           FormRow := FormRow +1
                                                        END;
                                             2 :  IF ixValues = Ord(cCoords)
                                                     THEN
                                                        BEGIN
                                                           ixValues := 1;
                                                           FormRow := 6
                                                        END
                                                     ELSE
                                                        BEGIN
                                                           ixValues := ixValues +1;
                                                           FormRow := FormRow +1
                                                        END;
                                             3 :  IF iyValues = Ord(cCoords)
                                                     THEN
                                                        BEGIN
                                                           CheckErc(SetFieldAttrs(
                                                                    ADS AlphaLineForm,
                                                                    ADS FldName[iNames+5,1],
                                                                    FldName[iNames+5].Len, 1,0));
                                                           iyValues := 1;
                                                           FormRow := 6;
                                                        END
                                                     ELSE
                                                        BEGIN
                                                           iyValues := iyValues +1;
                                                           FormRow := FormRow +1
                                                        END;
                                          OTHERWISE;
                                          END;
                                       END;{Case}
                           OTHERWISE ;
                           END;
                        END;{DownArrow}
         OTHERWISE
            BEGIN
               CASE FormRow OF
                  1 :  FormRow := 2;
                  2 :  FormRow := 3;
                  3 :  FormRow := 4;
                  4 :  FormRow := 5;
                  5 :  FormRow := 6;
               OTHERWISE
                  BEGIN
                     CASE FormColumn OF
                        1 :  IF iNames = Ord(cLines)
                                THEN
                                   BEGIN
                                      iNames := 1;
                                      ixValues := 1;
                                      FormRow := 6;
                                      FormColumn := 2
                                   END
                                ELSE
                                   BEGIN
                                      iNames := iNames + 1;
                                      FormRow := FormRow +1
                                   END;
                        2 :  IF ixValues = Ord(cCoords)
                                THEN
                                   BEGIN
                                      ixValues := 1;
                                      iyValues := 1;
                                      FormColumn := 3;
                                      FormRow := 6
                                   END
                                ELSE
                                   BEGIN
                                      ixValues := ixValues +1;
                                      FormRow := FormRow +1
                                   END;
                        3 :
                             BEGIN
                                IF (iNames =Ord(cLines)) AND
                                   (iyValues =Ord(cCoords))
                                   THEN
                                      BEGIN
                                         FormRow := 1;
                                         fEdit := True;
                                         CheckErc(DefaultField(ADS AlphaLineForm, ADS FldName[20,1],FldName[20].Len,0));
                                         CheckErc(SetFieldAttrs(ADS AlphaLineForm, ADS FldName[iNames+5,1], FldName[iNames+5].Len,
                                                                1, 0));
                                         FormColumn := 1
                                      END
                                   ELSE
                                      BEGIN
                                         IF iyValues = Ord(cCoords)
                                            THEN
                                               BEGIN
                                                  CheckErc(SetFieldAttrs(ADS AlphaLineForm, ADS FldName[iNames+5,1],
                                                                         FldName[iNames+5].Len, 1,0));
                                                  iNames := iNames +1;
                                                  iyValues := 1;
                                                  FormRow := 6;
                                               END
                                            ELSE
                                               BEGIN
                                                  iyValues := iyValues +1;
                                                  FormRow := FormRow +1
                                               END
                                      END
                             END;
                     OTHERWISE;
                     END{Case}
                  END
               END{Case}
            END;
         END;{Case of ExitState.ch}

(**)
(* Check that all required fields have been entered, *)
(* if not, set the form row  column to where the    *)
(* entry is in error and activate that field.        *)
(**)
         IF (fDone AND fGraph)
            THEN
               FOR I := Ord(cLines) DOWNTO 1 DO
                  IF LineName[I].Len = 0
                     THEN
                        BEGIN
                           Beep;
                           WriteStatusLine(ADS AlphaLineForm, 'Invalid or missing entry',0,False);
                           iNames := I;
                           FormRow := I+5;
                           FormColumn := 1;
                           fDone := False
                        END;

         IF (fDone AND fGraph)
            THEN
               FOR J := Ord(cCoords) DOWNTO 1 DO
                  IF xValue[J].Len = 0
                     THEN
                        BEGIN
                           Beep;
                           WriteStatusLine(ADS AlphaLineForm, 'Invalid or missing entry',0,False);
                           ixValues := J;
                           FormRow := J+5;
                           FormColumn := 2;
                           fDone := False
                        END;

      END; {While Not(fDone)}

   CheckErc(UnDisplayForm(ADS AlphaLineForm));
   IF fGraph
      THEN
         BEGIN
            SaveALineData(DataSpec);
            ZipBGP
         END;

END;{Procedure}
END.
  2 :  FormRow := 3;
                  3 :  FormRow := 4;
                  4 :  FormRow := 5;
                  5 :  FormRow := 6;
               OTHERWISE
                  BEGIN
                     CASE FormColumn OF
                        1 :  IF iNames = Ord(cLines)
                                THEN
                                   BEGIN
                                      iNames := 1;