From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: type conversion question
Date: 2000/08/16
Date: 2000-08-16T00:00:00+00:00 [thread overview]
Message-ID: <8WEm5.2477$2l4.33427@newsread2.prod.itd.earthlink.net> (raw)
In-Reply-To: 399AF3F8.A5596932@tridsys.com
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;
>
>
>
>
next parent reply other threads:[~2000-08-16 0:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <399AF3F8.A5596932@tridsys.com>
2000-08-16 0:00 ` David C. Hoos, Sr. [this message]
2000-08-17 0:00 ` type conversion question M. Kotiaho
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox