[comp.lang.pascal] Request: Help with Enumeration Type

gaertner@tertius.in-berlin.de (12/13/90)

To write values of an enumeration-type onto an external file you have to
use the PUT routine. The following short program shows the way on a VAX.




PROGRAM Test ( OUTPUT, DataFile ) ;

TYPE Measure = ( low , high ) ; { our enumeration type }

VAR  result : FILE OF Measure ; { the logical file }

BEGIN

{ create system dependent connection of logical/external file
  we create a new file                                        }
OPEN(FILE_VARIABLE:=result,FILE_NAME:='TEST.DAT',HISTORY:=NEW) ;

{ put `result' into generation-mode }
REWRITE(result) ;

{ fill the file buffer }
result^:=low ;

{ now write the value onto the file }
PUT(result) ;

{ destroy system dependent connection of logical/external file }
CLOSE(result) ;

{ create a new connection of logical/external file
  we want to read the previously written value     }
OPEN(FILE_VARIABLE:=result,FILE_NAME:='TEST.DAT',HISTORY:=OLD) ;

{ put `result' into inspection-mode; also the file buffer is filled
  with the first element }
RESET(result) ;

{ check the element }
IF result^=low WRITELN(' got the value ') ;

{ destroy system dependent connection of logical/external file }
CLOSE(result) ;

END.



-----

   Ralf Gaertner             e-mail:  gaertner@fhi-berlin.mpg.dbp.de
   Fritz-Haber-Institute (FRG)

g_harrison@vger.nsu.edu (12/14/90)

In article <6213@tertius.in-berlin.de>, gaertner@tertius.in-berlin.de writes:
> To write values of an enumeration-type onto an external file you have to
> use the PUT routine. The following short program shows the way on a VAX.
> 
> 
> 
> 
> PROGRAM Test ( OUTPUT, DataFile ) ;
[etc.]

No, the use of PUT is not necessary in VAX Pascal.  Try

program ETEST (FUZZY_FILE, OUTPUT);
type
	FUZZY = (YES, NO, PERHAPS);
var
	FUZZY_FILE : FILE of FUZZY;
	F : FUZZY;
begin
	REWRITE(FUZZY_FILE);		{External will be FUZZY_FILE.DAT}
	for F := PERHAPS downto YES do
		WRITE(FUZZY_FILE, F);

	RESET(FUZZY_FILE);
	while not EOF(FUZZY_FILE) do
	begin
		READ(FUZZY_FILE, F);
		WRITELN(F)
	end
end.

Output is
PERHAPS
NO
YES

This is NOT a flame.  I too prefer to use the PUT routine on sequential files.

George....

------------------------------------------------------*------o    Happy---
-- George C. Harrison ------------------------------ * * ----o_o___ New---
----- Professor of Computer Science --------------  * * * ----\ o /-Year--
----- Norfolk State University, -----------------  *Merry* ----\ /--------
-------- Norfolk, Virginia 23504 ---------------  * * * * * ----|---------
----- INTERNET:  g_harrison@vger.nsu.edu ------  *Christmas* --_|_--------
----------These are MY views.... you may share them..*** -----------------