Article View: comp.lang.modula2
Article #4853Re: type conversion question
From: Daniel J. Salomon
Date: Thu, 01 Jun 1989 17:06
Date: Thu, 01 Jun 1989 17:06
18 lines
1225 bytes
1225 bytes
In article <2027@csuna.csun.edu> abcscagz@csuna.csun.edu (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?
> ... 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?
>
Use the standard procedure VAL. E.g.
ReadInt (i);
enumvar := VAL (enumtype, i);
See section 10.2 of "Programming in Modula-2" by Niklaus Wirth.
A better book (clearer and a lot shorter) is "Modula-2 for Pascal
Programmers" by Richard Gleaves, section 11.6. This book has a
usable index, not like Wirth's book.
Technical Details
Message-ID:
<14226@watdragon.waterloo.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!uwvax!tank!uxc!iuvax!watmath!watdragon!djsalomonReferences:
<2027@csuna.csun.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!uwvax!tank!uxc!iuvax!watmath!watdragon!djsalomon From: djsalomon@watdragon.waterloo.edu (Daniel J. Salomon) Newsgroups: comp.lang.modula2 Subject: Re: type conversion question Message-ID: <14226@watdragon.waterloo.edu> Date: 1 Jun 89 17:06:27 GMT References: <2027@csuna.csun.edu> Reply-To: djsalomon@watdragon.waterloo.edu (Daniel J. Salomon) Organization: U. of Waterloo, Ontario Lines: 18