comp.lang.ada
 help / color / mirror / Atom feed
From: "Justin Birtwell" <jbirtwell@yahoo.com>
Subject: Re: Newbie question on Ada TExt_IO
Date: Fri, 04 Oct 2002 17:34:42 GMT
Date: 2002-10-04T17:34:42+00:00	[thread overview]
Message-ID: <Sikn9.1513$Mw4.1034@nwrddc01.gnilink.net> (raw)
In-Reply-To: 93d4dcd4.0210031020.b0cca2b@posting.google.com

Hello All,

To everyone that replied to my question..thank you.  Through your responses
I learned allot.  I learned how I could raise an error with in a loop by
nesting a block,  I also learned about Skip_Line and Get_Line, the
Ada.Strings.Trim and the Ada.Strings.Fixed.Index packages.  After reading
everyone's post I"ve decided that the best course of action is to validate
the input as much as I possibly can but still supply some exception handling
for anything that I haven't anticipated.  So my validation looks like this

Accept entire line using Get_Line into string(1..256);
Check if first character is a digit
Check if digit is between 1 and 6
error handling

Here's the code:

with Text_Io;use Text_Io;
with StringFunctions;use StringFunctions;

procedure Test_IO_2 is
   Input: String(1..256);
   N:Integer;
   Success:Boolean:=false;
   Last:Integer;
begin
      while success /=true loop
      Put("PLease enter a number between 1 and 6");
      Get_Line(Item=>Input,Last=>Last);
         if Is_Digit(Input(1..1)) then
            N:=Integer'Value(Input(1..1));
            if N>=1 and N<=6 then
               Success:=True;
            end if;
         else
            success:=false;
            Put_Line("Invalid entry, try again.");
         end if;
       end loop;
      Put_Line("Thank you");
     exception
      when others=>
         Put_Line("Error, Invalid data.");
end;

Is_Digit a hack of a procedure that compares the 1 character string to all
10 digits characters.  I really have a lot to learn.   What's giving me the
hardest time is working within the confines of strict/strong typing.  The
Ada.Characters.Handling  package already has an Is_Digit function, but it's
expecting a character not a single item String array!  How can I convert
from one into the other?  I have the distinct feelling like I'm reinventing
the wheel.  Aren't packages aready made to do alot of this
converting/validation?  If so where are they?  How can one access them?
Does the RM list all the packages provided by Ada or are there more to be
discovered?

thanks to one and all,
Justin







  parent reply	other threads:[~2002-10-04 17:34 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-03 18:20 Newbie question on Ada TExt_IO Justin
2002-10-03 18:50 ` Matthew Heaney
2002-10-03 19:05 ` Jeffrey Carter
2002-10-03 19:35 ` David C. Hoos
2002-10-03 19:35 ` tmoran
2002-10-03 19:43 ` Preben Randhol
2002-10-03 19:55   ` Matthew Heaney
2002-10-03 20:07     ` Preben Randhol
2002-10-04  2:42 ` SteveD
2002-10-04 17:49   ` Justin Birtwell
2002-10-04 18:00     ` David C. Hoos
2002-10-04 18:04       ` Preben Randhol
2002-10-04 18:00     ` Preben Randhol
2002-10-04 18:02       ` Preben Randhol
2002-10-04 18:34     ` tmoran
2002-10-04 17:34 ` Justin Birtwell [this message]
2002-10-04 17:58   ` Preben Randhol
2002-10-04 18:13   ` tmoran
2002-10-04 20:07   ` Jeffrey Carter
2002-10-07  8:26     ` Fraser Wilson
2002-10-07 19:44       ` Jeffrey Carter
2002-10-05  2:43   ` SteveD
2002-10-05  5:25     ` tmoran
  -- strict thread matches above, loose matches on Subject: below --
2002-10-07  6:01 Grein, Christoph
2002-10-07  8:27 Grein, Christoph
2002-10-07 11:48 ` Fraser Wilson
2002-10-07 12:46   ` Robert A Duff
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox