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.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM,XPRIO autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b031f1e9322936f1,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-05-20 16:09:41 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!sunqbc.risq.qc.ca!newsfeed.telusplanet.net!peer1-sjc1.usenetserver.com!usenetserver.com!pd2nf1so.cg.shawcable.net!residential.shaw.ca!news1.calgary.shaw.ca.POSTED!not-for-mail X-Trace-PostClient-IP: 24.68.22.66 From: "tr4ck" Newsgroups: comp.lang.ada Subject: Constraint error help.. X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Message-ID: Date: Mon, 20 May 2002 23:09:37 GMT NNTP-Posting-Host: 24.69.255.206 X-Complaints-To: abuse@shaw.ca X-Trace: news1.calgary.shaw.ca 1021936177 24.69.255.206 (Mon, 20 May 2002 17:09:37 MDT) NNTP-Posting-Date: Mon, 20 May 2002 17:09:37 MDT Organization: Shaw Residential Internet Xref: archiver1.google.com comp.lang.ada:24437 Date: 2002-05-20T23:09:37+00:00 List-Id: I am getting a constraint error for this line Word_Array(I) := Word; and I can't figure out why, the program compiles fine. Below is the code for the program. The program reads in a text file, say the file has the line, This is a test, it just reads character by character seeing if the item is actually a character if so it puts it into a string called word. Then the word gets put into an word_Array. This is something simple that I am trying, so it just returns if the item is not a character or if their are spaces. Can someone tell my why I am getting a constaint error? Thanks. WITH Ada.Text_IO; WITH Ada.Characters.Handling; WITH Ada.IO_Exceptions; PROCEDURE FileArray IS FileName : String(1..80); MaxName : CONSTANT Positive := 80; SUBTYPE NameRange IS Positive RANGE 1..MaxName; Length : NameRange; DataFile : Ada.Text_IO.File_Type; Letter : Character; Word : String(1..10); I : Integer := 0; Word_Array : ARRAY(1..30) OF String(1..10); PROCEDURE OpenFile IS --Opens a file BEGIN LOOP BEGIN Ada.Text_IO.Put(Item => "Enter the name of the file > "); Ada.Text_IO.Get_Line(Item => FileName, Last => Length); Ada.Text_IO.Open(File => DataFile, Mode => Ada.Text_IO.In_File, Name => FileName(1..Length)); Ada.Text_IO.Put("File Opened"); EXIT; EXCEPTION WHEN Constraint_Error => Ada.Text_IO.Put(Item => "Constraint Error! "); Ada.Text_IO.Skip_Line; WHEN Ada.Text_IO.Data_Error => Ada.Text_IO.Put(Item => "Data Error! "); Ada.Text_IO.Skip_Line; WHEN Ada.Text_IO.End_Error => Ada.Text_IO.Put(Item => "End Error! "); Ada.Text_IO.Skip_Line; WHEN Ada.IO_Exceptions.Status_Error => Ada.Text_IO.Skip_Line; WHEN Ada.IO_Exceptions.Name_Error => Ada.Text_IO.New_Line; Ada.Text_IO.Put_Line ("Cannot Open " & FileName(1..Length) & "!"); Ada.Text_IO.New_Line; END; END LOOP; END OpenFile; PROCEDURE Convert IS -- Changes the characters to lowercase BEGIN LOOP EXIT WHEN Ada.Text_IO.End_Of_File(File => DataFile); LOOP EXIT WHEN Ada.Text_IO.End_Of_Line(File => DataFile); Ada.Text_IO.Get(File => DataFile, Item => Letter); Letter := Ada.Characters.Handling.To_Lower(Item => Letter); END LOOP; Ada.Text_IO.Skip_Line(File => DataFile); END LOOP; END Convert; PROCEDURE CheckChar IS -- Check one item at a time to see if its a character, -- if it is then it puts it in the word string BEGIN LOOP IF Letter IN 'a'..'z' THEN Word(I) := Letter; ELSE RETURN; END IF; I := I + 1; END LOOP; END CheckChar; PROCEDURE Store IS -- Puts the words in the word_array BEGIN I := 0; LOOP IF I <= 30 THEN Word_Array(I) := Word; ELSE RETURN; END IF; I := I + 1; END LOOP; END Store; PROCEDURE Display IS -- Displays the contents of the word array BEGIN I := 1; LOOP Ada.Text_IO.Put(Item => Word_Array(I)); I := I + 1; END LOOP; END Display; BEGIN OpenFile; Convert; CheckChar; Store; Display; END FileArray;