Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!shadooby!samsung!uunet!mcsun!hp4nl!dutrun!winfave From: winfave@dutrun.UUCP (Alexander Verbraeck) Newsgroups: comp.lang.pascal Subject: Re: Another various question about TP 5.0 Message-ID: <1017@dutrun.UUCP> Date: 4 Dec 89 14:43:38 GMT References: <303@usna.MIL> Reply-To: winfave@dutrun.UUCP (A.Verbraeck) Organization: Delft University of Technology, The Netherlands Lines: 47 In article <303@usna.MIL> baldwin@cad.usna.mil (J.D. Baldwin) writes: >Is there a good, clean way to convert the value of an enumerated ordinal >type to a string value? > >That is, what does the function ConverterFunction(somevalue:sometype) : string >look like in this fragment: > > type veggies = (carrots, limabeans, beets, toadstools); . . . > var whatveg : veggies; . . . > > whatveg := carrots; > . . . > writeln(ConverterFunction(whatveg)); > >so that the writeln statement will output the string "carrots"? This question >is not exactly mission-critical to me, but an answer would be nice. If >replies are by e-mail, I'll summarize. The way I usually solve this is as follows (Turbo Pascal 3, 4, 5, ...): program vegetables(input,output); type VegType = (carrot, apple); const VegString : array[VegType] of string[10] = ('carrot','apple'); var V : VegType; begin V:=carrot; writeln(VegString[V]); readln; end. I think it is a neat way to do it: using strings of the defined type array[VegType]. In this way you don't need any conversion function, case statement or whatever. ---------------------------------------------------------------------- Alexander Verbraeck e-mail: winfave@dutrun.tudelft.nl Delft University of Technology winfave@hdetud1.bitnet Department of Information Systems winfave@dutrun.uucp PO Box 356, 2600 AJ The Netherlands dutrun!winfave@hp4nl.uucp ----------------------------------------------------------------------