[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
(*   NOTE - This source code was included with the tutor ZIP, simply because
            the more source you have to look at, the easier it is to learn.
            This source code is NOT mentioned or used as an example in the
            TUTOR_1.DOC file though.  However, examine it, and you might
            learn something.

GET_STATS.PAS
Renegade Programmer's Guide
by Douglas Good, P/S Programming

This program shows how to open RENEGADE.DAT and read information from it.
Proper error checking is demonstrated.  Be sure to make a BACKUP COPY of
your Renegade.Dat file if you decide to experiment with this program!!
(ALWAYS better safe than sorry!!!!)

Definition of Procedures:

Get_Stats  -  Opens the Renegade.Dat file, and reads it into memory.
Do_Error   -  Called if there's an error opening the Renegade.Dat file.
Show_Info  -  Displays some information about your BBS, which was read from
              the Renegade.Dat file.


*)

Uses
    crt;                       { Include the CRT unit for screen procedures  }

{$I Records.pas}                { Include the Record Structures in the        }
                                { Records.pas file, distributed by Cott Lang  }


Type
   Statfile = file of GeneralRec;    {  The TYPE of file Renegade.Dat is     }

Var
   Stats : Statfile;                 { Declare Stats as our file variable    }
   StatRecord : GeneralRec;          { The variable which holds the record
                                       in memory.  (Renegade.Dat is only one
                                       big record)                          }


(**************************************************************************
Procedure Do_Error:  Displays an error message on the screen, telling the
                     user that Renegade.Dat could not be opened.  This is
                     most often caused because the user did not run the
                     program from his main BBS directory, where Renegade.Dat
                     is located.
***************************************************************************)
Procedure Do_Error;
  Begin
     Clrscr;                            { Clear the Screen                 }
     Textcolor(12);                     { Set bright orange text color     }

     Writeln('ERROR OCCURED opening Renegade.Dat!');

     Textcolor(15);                     { Set bright white text color      }

     Writeln('Be sure to run this program from your main BBS directory.');
  End; { Procedure Do_Error}




(**************************************************************************
 Procedure Get_Stats:  Opens and reads the Renegade.Dat file into the
                       variable StatRecord.  If there's an error during
                       the opening of Renegade.Dat, calls Do_Error and
                       exits back to DOS.
 **************************************************************************)
Procedure Get_Stats ( var StatRecord : GeneralRec );
  Begin
     Assign(Stats,'Renegade.dat');    { Assign Renegade.Dat to our file
                                        variable.}
     {$I-}                            { Turn off error checking in case there's
                                        an error }
     Reset(Stats);                    { Open Renegade.Dat for reading      }
     {$I+}                            { Error checking turned back on  now }
     If IOResult = 0 then             { If no errors opening file, begin   }
       Begin
         Read(Stats,StatRecord);      { Read Renegade.Dat into StatRecord  }
         Close(Stats);                { Close the file back up             }
       End
     Else                             { Else if we DID get an error, begin }
       Begin
         Do_Error;                    { Display Error Message              }
         Halt;                        { Exit program                       }
       End;
  End; { Procedure Get_Stats }




(**************************************************************************
Procedure Show_Info:  This procedure uses the information contained in
                      StatRecord to display some info about your BBS.
***************************************************************************)
Procedure Show_Info(StatRecord: GeneralRec);
  Begin
     ClrScr;                               { Clear the Screen             }
     Textcolor(11);
     Writeln(' RENEGADE BBS DATA');
     Textcolor(10);
     Writeln;
     Writeln('Sysop''s Name :  ',StatRecord.SysopName);  { Show Sysop's name   }
     Writeln('BBS Name     :  ',StatRecord.BbsName);     { Show BBS Name       }
     Writeln('BBS Phone    :  ',StatRecord.BbsPhone);    { Show BBS Phone No.  }
     Writeln;
     Textcolor(14);
     Writeln('Number of Users:  ',StatRecord.Numusers);  { Number of Users     }
  End;



(**************************************************************************
Main Program - Calls Get_Info to read the Renegade.Dat file, and if there's
               no error, will call Show_Info to display some information
               about the BBS.
***************************************************************************)

Begin { Main Program }                     { Main program Begins here     }

      Get_Stats(StatRecord);               { Call Get_Stats, and send the
                                             StatRecord along as a variable
                                             parameter, since Get_Stats will
                                             fill it with info.            }

      Show_Info(StatRecord);               { Call the Show_Info Procedure to
                                             Display information from the
                                             Renegade.Dat file.            }

End.                                       { End the program.              }
.

This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson