ZCCBJSB%EB0UB011.BITNET@cunyvm.cuny.edu (Josep Sau B.) (12/11/90)
From: Arne Gehlhaar <Arne.Gehlhaar@arbi.informatik.uni-oldenburg.de> Subject: Reuqest : Help with Enumeration Types Date: 10 Dec 90 08:29:12 GMT To: info-pascal@BRL.MIL >I have a problem with enumeration types. >... >What do I have to do in order for the compiler to accept input >and output ? You asked 'so what is the use of this types...?' The enumerated types are disguised integer types that make easier to compiler (and programmer) not to add apples and bananas - so is do not mix in expressions data of different types. These are ordinal types that only accept a subset of operators applicable to integers: Succ(), Pred(), Ord(), the relational operators < = >, and others specifics of Turbo (like Inc(), Dec()...). How to do input/output with types like those ? You'll have to choose one of these implementations: a) Declare a CONST id ARRAY(.YourEnumeratedType.) OF STRING(.n.) 'id' is the identifier of the array of string. 'n' is the maximum length of the name of an element in the type. YourEnumeratedType is just that, the identifier you chose. This way you can OUTPUT easily with 'Write(id(.x.)). To INPUT you should enter a string, and then scan array searching for the one matching - and reject it if not found. b) Do a similar trick using a CASE statements using all constants of the enumerated type as labels. Do specific routines ReadMyEnumerated, WriteMyEnumerated ... Anyway, remember that his types are internally implemented as plane integer types ranging from 0 to NumberOfElementsInType -1. --Josep Sau B. <ZCCBJSB@EB0UB011> P.S. You probably knew all this stuff, but I got the literary trip. ------------------------------------------------------------------ 'Every science needs the right words to be expressed the right way' Raimundus Lulius (Catalan philosopher) ------------------------------------------------------------------