comp.lang.ada
 help / color / mirror / Atom feed
* Getting a one-touch option (was: Ada95 tutorials with sample code)
       [not found] <B6A1A9B09E52D31183ED00A0C9E0888C469A44@nctswashxchg.nctswash.navy.mil>
@ 2001-03-07 11:50 ` Mario Amado Alves
  2001-03-08 18:10   ` mcdoobie
  0 siblings, 1 reply; 4+ messages in thread
From: Mario Amado Alves @ 2001-03-07 11:50 UTC (permalink / raw)
  To: 'comp.lang.ada@ada.eu.org'

> procedure Xyz is
> 
>   opt_is : character := ' ';
> 
> begin
> 
>   while opt_is /= 'V' and then opt_is /= 'A' loop
>     Put( opt_prompt );
>     NEW_LINE;
>     Ada.Text_IO.Put_Line( "Please enter either a 'V' or an 'A' );
>     Get( opt_is );
>     opt_is := To_Upper(opt_is);
>   end loop;
> 
> end Xyz;

Lately I have been using enumerations and exceptions for this kind of
problem:

  type Options is (A, V);
  Option: Options;
  C: Character;
begin
  loop
    Put("Please enter either a 'V' or an 'A'");
    Get_Immediate(C);
    begin
      Option := Options'Value(C & "");
      exit;
    exception
      when Constraint_Error => null;
    end;
  end loop;

There is of course more to be said about "exception-oriented" programming. 
Let us save that for the Ada-Europe'2001 workshop ;-)

| |,| | | |RuaFranciscoTaborda24RcD 2815-249CharnecaCaparica 351+939354005
|M|A|R|I|O|
|A|M|A|D|O|DepartmentoDeInformaticaFCT/UNL 2825-114 Caparica 351+212958536
|A|L|V|E|S|                                                  fax 212948541
| | | | | |                 maa@di.fct.unl.pt                FCT 212948300






^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Getting a one-touch option (was: Ada95 tutorials with sample code)
  2001-03-07 11:50 ` Getting a one-touch option (was: Ada95 tutorials with sample code) Mario Amado Alves
@ 2001-03-08 18:10   ` mcdoobie
  2001-03-08 18:49     ` Marin David Condic
  2001-03-08 19:21     ` tmoran
  0 siblings, 2 replies; 4+ messages in thread
From: mcdoobie @ 2001-03-08 18:10 UTC (permalink / raw)


In article <mailman.983965508.309.comp.lang.ada@ada.eu.org>, "Mario Amado
Alves" <maa@di.fct.unl.pt> wrote:

> Lately I have been using enumerations and exceptions for this kind of
> problem:
> 
>   type Options is (A, V); Option: Options; C: Character;
> begin
>   loop
>     Put("Please enter either a 'V' or an 'A'"); Get_Immediate(C); begin
>       Option := Options'Value(C & ""); exit;
>     exception
>       when Constraint_Error => null;
>     end;
>   end loop;
> 
> There is of course more to be said about "exception-oriented"
> programming.  Let us save that for the Ada-Europe'2001 workshop ;-)

The whole use of types in Ada has kinda got me confused.

For example...

	the_volume := find_volume( aLength, aWidth, aHeight);

Gives me the error message on compile ...

	"array type required in indexed component"

This is NOT an array, it's a function call.

Heh, I guess I'll be hitting the books again.

Exceptions are something I plan on playing with soon. As soon as I got
all the basics worked out.

McDoobie

Thanks.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Getting a one-touch option (was: Ada95 tutorials with sample code)
  2001-03-08 18:10   ` mcdoobie
@ 2001-03-08 18:49     ` Marin David Condic
  2001-03-08 19:21     ` tmoran
  1 sibling, 0 replies; 4+ messages in thread
From: Marin David Condic @ 2001-03-08 18:49 UTC (permalink / raw)


Check your declaration of find_volume and make sure it matches the usage.
Its possible that you don't have find_volume visible or that the parameters
or return type are incorrect. The problem is that a function call can look
identical to an array reference syntactically. The compiler can't tell the
difference in the absence of other information. If you missed the
declaration entirely (or it isn't visible) you might get this error.

MDC
--
Marin David Condic
Senior Software Engineer
Pace Micro Technology Americas    www.pacemicro.com
Enabling the digital revolution
e-Mail:    marin.condic@pacemicro.com
Web:      http://www.mcondic.com/


"mcdoobie" <chainsawtwothousand@nospam.dot.home.dot.com> wrote in message
news:eWPp6.37842$W05.7762543@news1.rdc1.mi.home.com...
> The whole use of types in Ada has kinda got me confused.
>
> For example...
>
> the_volume := find_volume( aLength, aWidth, aHeight);
>
> Gives me the error message on compile ...
>
> "array type required in indexed component"
>
> This is NOT an array, it's a function call.
>
> Heh, I guess I'll be hitting the books again.
>
> Exceptions are something I plan on playing with soon. As soon as I got
> all the basics worked out.
>
> McDoobie
>
> Thanks.





^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Getting a one-touch option (was: Ada95 tutorials with sample code)
  2001-03-08 18:10   ` mcdoobie
  2001-03-08 18:49     ` Marin David Condic
@ 2001-03-08 19:21     ` tmoran
  1 sibling, 0 replies; 4+ messages in thread
From: tmoran @ 2001-03-08 19:21 UTC (permalink / raw)


>        the_volume := find_volume( aLength, aWidth, aHeight);
>
>        "array type required in indexed component"
>
>This is NOT an array, it's a function call.

  *You* know it's a function call.  Check the source code where
you *thought* you had told the compiler it was a function call.



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-03-08 19:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <B6A1A9B09E52D31183ED00A0C9E0888C469A44@nctswashxchg.nctswash.navy.mil>
2001-03-07 11:50 ` Getting a one-touch option (was: Ada95 tutorials with sample code) Mario Amado Alves
2001-03-08 18:10   ` mcdoobie
2001-03-08 18:49     ` Marin David Condic
2001-03-08 19:21     ` tmoran

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