From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID, T_FILL_THIS_FORM_SHORT autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,691bbbf0ab0cc67e X-Google-Attributes: gid103376,public From: mheaney@ni.net (Matthew Heaney) Subject: Re: [Q] Returning Strings From A Function Date: 1997/04/06 Message-ID: #1/1 X-Deja-AN: 231215185 References: <33454165.1658515@news.demon.co.uk> <33468b81.762963@news.demon.co.uk> <33478738.2129057@news.demon.co.uk> Organization: Estormza Software Newsgroups: comp.lang.ada Date: 1997-04-06T00:00:00+00:00 List-Id: In article <33478738.2129057@news.demon.co.uk>, john@assen.demon.co.uk (John McCabe) wrote: > >>John, it is still very difficult to understand what you are asking for. >>Your code above makes perfect sense if you want File_Name to be 12 characters >>long, and of course the assignment will check for 12 characters. > >Exactly - but I want the assignment to check for <=12 characters. In Ada 83, you can just assign the function return value to a (constant) object, and then do whatever you want with it (including assigning it to a fixed-length string). For example, subtype Name_String is String (1 .. 12); procedure Get_Name (Name : out Name_String) is The_Name : constant String := Text_IO.Name (The_File); Pad_Length : constant Natural := Name'Length - The_Name'Length; Pad : constant String (1 .. Pad_Length) := (others => ' '); begin Name := The_Name & Pad; end; A hipper technique is to use a string buffer, as follows: subtype Name_Length_Range is Natural range 0 .. 12; type Name_Buffer (Length : Name_Length_Range := 0) is record Name : String (1 .. Length); end record; procedure Get_Name (Name : out Name_Buffer) is The_Name : constant String := Text_IO.Name (The_File); begin Name := (The_Name'Length, The_Name); end; Hope that helps, Matt -------------------------------------------------------------------- Matthew Heaney Software Development Consultant (818) 985-1271