comp.lang.ada
 help / color / mirror / Atom feed
* Re: type conversion question
       [not found] <399AF3F8.A5596932@tridsys.com>
@ 2000-08-16  0:00 ` David C. Hoos, Sr.
  2000-08-17  0:00 ` M. Kotiaho
  1 sibling, 0 replies; 2+ messages in thread
From: David C. Hoos, Sr. @ 2000-08-16  0:00 UTC (permalink / raw)


To obtain a string from a scalar type, you need to use 'Image,
which is just the opposite of 'Value.

"Raju Vemulamanda" <raju@tridsys.com> wrote in message
news:399AF3F8.A5596932@tridsys.com...
> Hi,
>     Could someone please clarify my doubt on the type conversion?
>      Somebody has answered my previous question through
> comp.lang.ada@ada.eu.org.
> Below is the question and the answer I got..
>    Now I am using the same way to do exactly opposite.
> I have an integer of type Integer_32 which is predefined in our code.
>  I want to convert it into a string.... like
>
>  type Integer_32 is new Base_Integer range -2 ** 31 .. 2 ** 31 - 1;
>  new_fieldvalue : Integer_32;
>
> what I am attempting to do is....
>
>      Text_Io.Put_Line(Vmf_File2, String'Value(new_fieldvalue));
>
> The error I am getting is ...
>      pretext of "Value" attribute must be scalar type
>
> whats wrong in it???
>
> Can someone please answer this..
>
> raju
>
> my previous question
>
> > Question: Could someone please provide some solution
> >   to the below?
> >
> > I have this question in the conversion of values
> > between the string and the my own type shown below.
> >
> > type Bit_5 is range 2#0# .. 2#11111#;
> >     for Bit_5'Size use 5;
> > subtype Size_Type is Bit_5;
> >
> > The above is how Size_Type has been declared.
> >
> > val1 : Jvmfr3_Field_Types.Size_Type := 10;
> >
> > Suppose I have a string xxx which has the some value in it,
> > How can I convert that xxx into the above declared val1?
> > I have to copy xxx into val1. I need to somehow do the
> > type casting for the above.
>
> answer:
>
> Here's a complete example:
>
> with Ada.Text_Io;
> procedure Size_Demo is
>
>   package Text_Io renames Ada.Text_Io;
>
>   type Bit_5 is range 2#0# .. 2#11111#;
>   for Bit_5'Size use 5;
>   subtype Size_Type is Bit_5;
>
>   val1 : Size_Type;
>   input_string : String(1..10);
>   last_char : Natural;
>
> begin
>    Text_Io.Put( "Enter Value => " );
>    Text_Io.Get_Line( input_string, last_char );
>    val1 := Size_Type'Value( input_string( 1 .. last_char ) );
>
>    Text_Io.Put_Line( "Value is: " & Size_Type'Image( val1 ) );
> end Size_Demo;
>
>
>
>






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

* Re: type conversion question
       [not found] <399AF3F8.A5596932@tridsys.com>
  2000-08-16  0:00 ` type conversion question David C. Hoos, Sr.
@ 2000-08-17  0:00 ` M. Kotiaho
  1 sibling, 0 replies; 2+ messages in thread
From: M. Kotiaho @ 2000-08-17  0:00 UTC (permalink / raw)




Raju Vemulamanda wrote:

> ...
> what I am attempting to do is....
>
>      Text_Io.Put_Line(Vmf_File2, String'Value(new_fieldvalue));
>

What you want is:
 Text_Io.Put_Line(Vmf_File2, Integer_32'Image(new_fieldvalue));

>

                    vvvvvvv
>> val1 : Jvmfr3_Field_Types.Size_Type := 10;
                    ^^^^^^
Aaaaaaaah!!!  Joint Variable Message Format (rev 3)!!!
Sorry about that, it is just surprising (to me) to see Ada code that I
have dealt with before...
speaking of which, how common of an occurrence is that -- to see Ada
code with which you are
familiar somewhere else?

Regards,
MK






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

end of thread, other threads:[~2000-08-17  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <399AF3F8.A5596932@tridsys.com>
2000-08-16  0:00 ` type conversion question David C. Hoos, Sr.
2000-08-17  0:00 ` M. Kotiaho

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