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,FREEMAIL_FROM, INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9b39dbd8effaa623 X-Google-Attributes: gid103376,public From: johnherro@aol.com (John Herro) Subject: Re: simple problem? Date: 1996/05/10 Message-ID: <4mvl9q$f1d@newsbf02.news.aol.com>#1/1 X-Deja-AN: 154128967 sender: root@newsbf02.news.aol.com references: organization: America Online, Inc. (1-800-827-6364) newsgroups: comp.lang.ada Date: 1996-05-10T00:00:00+00:00 List-Id: Frank Cheung gets an error compiling a program containing: > package TEXT_IO is new SEQUENTIAL_IO(STRING); If you're using an Ada83 compiler, you must instantiate SEQUENTIAL_IO with a *constrained* type or subtype. STRING is an unconstrained type. In a moment I'm going to tell you that you don't want to instantiate SEQUENTIAL_IO at all, but for instructional purposes, I'll show you how to do it before we throw the idea away! First, there's already a TEXT_IO package in Ada, so, to avoid confusion, you would want to use another name for your package. How about HOAX_IO? You could write: subtype Time_Of_Call_Subtype is STRING(1 .. 12); package HOAX_IO is new SEQUENTIAL_IO(Time_Of_Call_Subtype); use HOAX_IO; and then you could write call times to your hoax file. *OR* you could write: subtype Caller_Description_Subtype is STRING(1 .. 400); package HOAX_IO is new SEQUENTIAL_IO(Caller_Description_Subtype); use HOAX_IO; and then you could write caller descriptions to your hoax file. The trouble is that you want to write *both* call times and caller descriptions to the same file. The package TEXT_IO that comes with Ada is just right for that. It's made for writing variable-length text records. So forget SEQUENTIAL_IO. You want to with and use TEXT_IO rather than instantiate SEQUENTIAL_IO. To correct your program, I made that change, and I created one declaration of CallFile : FILE_TYPE; in the main program, rather than one in each subprogram, so that each subprogram could write to the same file. Because we're using TEXT_IO, I changed every "write" to "Put_Line." I made CREATE_HOAX_FILE create the file and write the header, but not close the file, because APPEND_HOAX_FILE will add to it. Likewise, I took the open and close out of APPEND_HOAX_FILE, and closed the file at the end of the main program. The procedure OUTPUT_HOAX_FILE is unnecessary, because, even without this procedure, you've created the file, appended to it, and closed it. Finally I removed the unused declarations of Time_Of_Call and Caller_Description in the main program. Here's your corrected program: with TEXT_IO; use TEXT_IO; procedure MAIN is FileName : STRING(1..12) := "hoaxfile.dat"; CallFile : FILE_TYPE; procedure CREATE_HOAX_FILE is begin Create(CallFile, NAME=>FileName); Put_Line(CallFile, "Hoax/Complaint file created on 9th May, 1996"); end CREATE_HOAX_FILE; procedure APPEND_HOAX_FILE(Time_Of_Call, Caller_Description:STRING) is begin Put_Line(CallFile, Time_Of_Call); Put_Line(CallFile, Caller_Description); end APPEND_HOAX_FILE; begin CREATE_HOAX_FILE; APPEND_HOAX_FILE("12:00", "Ben"); APPEND_HOAX_FILE("12:15", "Adam"); APPEND_HOAX_FILE("18:00", "Frank"); Close(CallFile); end MAIN; Here's the output file hoaxfile.dat after your program is run: Hoax/Complaint file created on 9th May, 1996 12:00 Ben 12:15 Adam 18:00 Frank Now, I suspect that you'll want to be able to append to the hoax file later. The best solution is to get an Ada95 compiler. You would still use Text_IO, but you would Open the hoax file in Append_File mode, which isn't available in Ada83. If you're stuck with an Ada83 compiler, the best way to "append" to a text file with variable-length records is, at the start of the program, to read the entire file a line at a time and write each line to a new file. When you get to the end of the input file, close it, but leave the output file open for further writing. At the end of your program, delete the input file and rename the output file. (The Ada95 solution is easier!) Ada is a large language that can be a bit confusing for beginners, but you'll find the people at comp.lang.ada eager to help you. Please don't hesitate to ask questions if any of this is unclear. - John Herro Software Innovations Technology http://members.aol.com/AdaTutor ftp://members.aol.com/AdaTutor