Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!mcvax!hp4nl!maestro!fransvo From: fransvo@maestro.htsa.aha.nl (Frans van Otten) Newsgroups: comp.lang.modula2 Subject: Re: type conversion question Message-ID: <951@maestro.htsa.aha.nl> Date: 1 Jun 89 14:39:43 GMT References: <2027@csuna.csun.edu> Reply-To: fransvo@htsa.UUCP (Frans van Otten) Organization: AHA-TMF (Technical Institute), Amsterdam The Netherlands Lines: 25 Jeff Boeing writes: >I couldn't find this anywhere in Wirth's book (4th edition), so here goes: > >How do you convert from a cardinal or integer type to an enumerated type? >I would like very much to keep a particular enumerated type in a program I'm >writing, but this program requires that some data of that type be written to >and read from a file. If x is of my enumerated type, it's easy enough to save >it to a file by saying "WriteInt (ORD(x))" (after redirecting output, of >course), but how do I read that value back in? I don't know about the 4th edition, but in the 3rd edition such a procedure is described. In paragraph 10.2, "Standard procedures", on page 162: VAL(T, x) The value with ordinal number x and with type T. T is any enumeration type, or CHAR, INTEGER, or CARDINAL. VAL(T, ORD(x)) = x, if x is of type T. ( Does anybody know why I never see anything about LONGINT or LONGREAL, except in the paragraph about basic types ? ) -- Frans van Otten | fransvo@maestro.htsa.aha.nl or Algemene Hogeschool Amsterdam | fransvo@htsa.uucp or Technische en Maritieme Faculteit | [[...!]backbone!]htsa!fransvo