comp.lang.ada
 help / color / mirror / Atom feed
* Getting valid Integer values !!
@ 2003-10-21 19:11 CheGueVerra
  2003-10-21 20:15 ` Martin Dowie
  0 siblings, 1 reply; 13+ messages in thread
From: CheGueVerra @ 2003-10-21 19:11 UTC (permalink / raw)


Hi guys it's me again,

Well after so much time playing with Ada I think I'm starting to get the
beat of it a special thanks to all those who have helped and will help down
the road...

Now, after testing a bit, this is the procedure I want to use to make sure
that the Integer values entered are valid and are in the range that I expect
them to be, it seems to be working fine, I'll test some more after the post,
but if you see some things that I Might have not thought of please tell me
so

[code snippet]
package Entiers is new Text_io.Integer_io (Num => Integer)

IntData : integer range 1000000..9999999;
ValidKey : Boolean := false;
begin
 put_line("Test Valid Key");

while not ValidKey loop
begin
    Put_line(" Enter Key :");
    Entiers.Get(IntData);
    ValidKey := True;
exception
    When Data_error | Constraint_error =>
        Put_line(" Error reading value,  Integer expected of range ...");
        Skip_line;
end;
end loop;

Put_Line("Valid data entered");
...

Keep in mind that I can't use an exit in a loop so I used the boolean value,
it seems to work but ada has surprised me before ....

TIA

CheGueVerra






^ permalink raw reply	[flat|nested] 13+ messages in thread
* RE: Getting valid Integer values !!
@ 2003-10-21 20:34 Beard, Frank Randolph CIV
  2003-10-21 21:34 ` CheGueVerra
  2003-10-21 21:36 ` CheGueVerra
  0 siblings, 2 replies; 13+ messages in thread
From: Beard, Frank Randolph CIV @ 2003-10-21 20:34 UTC (permalink / raw)
  To: CheGueVerra, comp.lang.ada

We have a similar loop that we used on our older
console interfaces.  Using your example, it would be:

...

   type IntData_Type is range 1000000..9999999;
   IntData  : IntData_Type := IntData_Type'first;
   ValidKey : Boolean := false;

   package Entiers is new Text_io.Integer_io (Num => IntData);

begin

   put_line("Test Valid Key");

   loop
      begin
         Put(" Enter Key : ");  --+ Not Put_Line
         Entiers.Get(IntData);
         New_Line(2);
         exit;
      exception
         When Data_error | Constraint_error =>
              New_Line;
              Put_line(" Error reading value,  Integer expected of range ...");
              Skip_line;
      end;
   end loop;

   Put_Line("Valid data entered");
...

I don't follow why you can't use an exit.

Frank

-----Original Message-----
From: CheGueVerra [mailto:chegueverra@hotmail.com]
Sent: Tuesday, October 21, 2003 15:12
To: comp.lang.ada@ada-france.org
Subject: Getting valid Integer values !!


Hi guys it's me again,

Well after so much time playing with Ada I think I'm starting to get the
beat of it a special thanks to all those who have helped and will help down
the road...

Now, after testing a bit, this is the procedure I want to use to make sure
that the Integer values entered are valid and are in the range that I expect
them to be, it seems to be working fine, I'll test some more after the post,
but if you see some things that I Might have not thought of please tell me
so

[code snippet]
package Entiers is new Text_io.Integer_io (Num => Integer)

IntData : integer range 1000000..9999999;
ValidKey : Boolean := false;
begin
 put_line("Test Valid Key");

while not ValidKey loop
begin
    Put_line(" Enter Key :");
    Entiers.Get(IntData);
    ValidKey := True;
exception
    When Data_error | Constraint_error =>
        Put_line(" Error reading value,  Integer expected of range ...");
        Skip_line;
end;
end loop;

Put_Line("Valid data entered");
...

Keep in mind that I can't use an exit in a loop so I used the boolean value,
it seems to work but ada has surprised me before ....

TIA

CheGueVerra



_______________________________________________
comp.lang.ada mailing list
comp.lang.ada@ada-france.org
http://www.ada-france.org/mailman/listinfo/comp.lang.ada



^ permalink raw reply	[flat|nested] 13+ messages in thread
[parent not found: <mailman.161.1066792253.25614.comp.lang.ada@ada-france.org>]

end of thread, other threads:[~2003-10-22 19:27 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-21 19:11 Getting valid Integer values !! CheGueVerra
2003-10-21 20:15 ` Martin Dowie
2003-10-21 20:27   ` CheGueVerra
2003-10-21 23:04     ` Martin Dowie
2003-10-21 23:35       ` CheGueVerra
2003-10-22  2:49         ` Steve
2003-10-22  0:46     ` Jeffrey Carter
2003-10-22  1:07       ` CheGueVerra
  -- strict thread matches above, loose matches on Subject: below --
2003-10-21 20:34 Beard, Frank Randolph CIV
2003-10-21 21:34 ` CheGueVerra
2003-10-21 21:36 ` CheGueVerra
     [not found] <mailman.161.1066792253.25614.comp.lang.ada@ada-france.org>
2003-10-22  3:46 ` Jeff C,
2003-10-22 19:27   ` Simon Wright

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