From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9adb0110470c093d X-Google-Attributes: gid103376,public From: "Matthew Heaney" Subject: Re: Safely converting String to Float ? Date: 1999/11/03 Message-ID: <38203f2a_1@news1.prserv.net>#1/1 X-Deja-AN: 543947955 Content-transfer-encoding: 7bit References: Content-Type: text/plain; charset="US-ASCII" X-Complaints-To: abuse@prserv.net X-Trace: 3 Nov 1999 13:56:58 GMT, 129.37.62.132 Organization: Global Network Services - Remote Access Mail & News Services Mime-version: 1.0 Newsgroups: comp.lang.ada Date: 1999-11-03T00:00:00+00:00 List-Id: In article , Preben Randhol wrote: > begin > Get(Tekst,Tall,Size); > Get(Tekst2,Tall_F,Size_F); > end; Use an exception handler: begin Get (Tekst, Tall, Size); exception when Data_Error => -- check this in the RM Put_Line (); end; begin Get (...); exception when Data_Error => Put_Line (...); end; A few more points: 1) If you're using type Float, you don't need to instantiate Text_IO.Float_IO, because there's a predefined package called Ada.Float_Text_IO. 2) If you use Get, then the last parameter is not a "size" of subtype "Integer," it indicates the last index position of the value image, and its subtype is "Natural." declare Image : String := ""; Value : Float; Last : Positive; begin Get (From => Image, Item => Value, Last => Last); exception when Data_Error => end; 3) You don't really need Float_Text_IO or Get; simply use the attribute Float'Value to convert the string: declare Image : String := ; Value : Float; begin Value := Float'Value (Image); exception when Constraint_Error => -- note different exception end; -- Evolution is as well documented as any phenomenon in science, as strongly as the earth's revolution around the sun rather than vice versa. Stephen Jay Gould, Time, 23 Aug 1999