Procedure Strip_Spaces;

{strips spaces from beginning and end of TempVar}
Begin
  If Length(TempVar) <> 0 Then
    While Copy(TempVar,1,1) = Chr(32) Do Delete(TempVar,1,1);
  If Length(TempVar) <> 0 Then Begin
    i:= Length(TempVar);
    While Copy(TempVar,i,1) = Chr(32) Do Begin
      Delete(TempVar,i,1);
      i:= i-1;
      End;
    End;
End; { procedure strip_spaces }




Procedure Gather_Input_Info;

Var
  LOF:  Integer;   { Length Of Field }

Begin
  Tab;
  LOF:= ((MaxY-1)*80+MaxX)-((MinY-1)*80+MinX)+1;
  TempVar:= '';
  For i:= 1 to LOF Do Begin
    TempVar:= TempVar + ScrBuf[XY];
    XY:= XY+1;
    End;
End;


Procedure Find_Error;

Begin
    GotoXY(2,25);
    TextBackground(LightGray);
    TextColor(Black);
    For i:= 1 to 65 Do Write(Chr(32));
    GotoXY(12,25);
    Write('Field must contain only number characters,.,-');
    Entry_Field:= Entry_Field - 1;
    Tab;
    While (not X > ErrorPos) Do
      Rt1;
    Done_Reading_Kbd:= False;
    Repeat
      ReadKbd;
    Until Done_Reading_Kbd;
    Entry_Field:= Entry_Field-1;
End;





Procedure Check_For_BadName(Name: Str12);

Var
  ch: Char;    { this is what we're going to check to make sure it's valid }
  Name_Len: Integer;  { length of the file name to be checked }
  Str1: String[1];
  x: Integer;   { position within the name }

Begin
  Str1:= Copy(Name,1,1);
  ch:= Str1;
  Name_Len:= Length(Name);
  x:= 1;
    While Not (x > Name_Len) Do Begin
      Str1:= Copy(Name,x,1);
      ch:= Str1;
      Good_Char:= (ch in ['a'..'z','A'..'Z','0'..'9','_','.','$','&',
                          '#','@','!','%','(',')','-','{','}','/','\']);
      If Not Good_Char Then Begin
          Sound(1000);
          Delay(100);
          NoSound;
          GotoXY(1,25);
          TextColor(Black);
          TextBackground(White);
          For x:= 1 to 78 Do
            Write(' ');
          GotoXY(4,25);
          Write('File name has an invalid character in it.');
          TextColor(Yellow);
          TextBackground(Black);
          x:= Name_Len;  { no need to go any further }
          BadName:= True;
          x:= x+1;
          End { if not Good_Char }
      Else Begin { it is a good char }
        If ((ch = '.') and (Name_Len - x > 3)) Then Begin
          Sound(1000);
          Delay(100);
          NoSound;
          GotoXY(1,25);
          TextColor(Black);
          TextBackground(White);
          For x:= 1 to 78 Do
            Write(' ');
          GotoXY(15,25);
          Write('File name ext may have no more that 3 characters.');
          TextColor(Yellow);
          TextBackground(Black);
          x:= Name_Len;  { no need to go any further }
          BadName:= True;
          End { If ((ch = '.') and (Name_Len - x > 3)) }
        Else
        x:= x+1; { let's look at the next one }
        End; { else it is a good char }
      End; { While Not (x > Name_Len) }
End; { Procedure Check_For_BadName }


Procedure Open_File;

Begin

  GotoXY(25,12);
  Write('Data File Name');
  Repeat
    TextColor(LightRed);
    GotoXY(30,13);
    Readln(File_Name);
    BadName:= False;
    Check_For_BadName(File_Name);
  Until Not BadName;
  TextColor(Yellow);
  Assign (Output_File, File_Name);
  {$I-} Reset(Output_File) {$I+};   {turn off I/O error checking}
  EXISTS:= (IOresult = 0);         {file does exist }
  If Not EXISTS Then Begin         {file does not exist}
    Rewrite(Output_File);
    Current_File_Pos:= FilePos(Output_File)+1;
    ClrScr;
    End
  Else         {IOresult = 0, therefore it is an existing file}
   Begin
    ClrScr;
    Seek(Output_File, FileSize(Output_File));
    Current_File_Pos:= FilePos(Output_File)+1;
   End;

End; { procedure open_file }


