home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / ada / 2516 < prev    next >
Encoding:
Text File  |  1992-09-02  |  5.8 KB  |  190 lines

  1. Newsgroups: comp.lang.ada
  2. Path: sparky!uunet!rayssd!swlvx2!swlraw.msd.ray.com!dep
  3. From: dep@swlraw.msd.ray.com (DONALD PRINCIOTTA)
  4. Subject: Re: ADA help Urgently Requested..Please!!!!
  5. Message-ID: <1992Sep2.213750.10499@swlvx2.msd.ray.com>
  6. Sender: news@swlvx2.msd.ray.com (NEWS USER)
  7. Organization: Raytheon Company, Tewksbury, MA
  8. References: <1992Sep1.211014.1@vmsclst1.sc.csupomona.edu>
  9. Date: Wed, 2 Sep 1992 21:37:50 GMT
  10. Lines: 178
  11.  
  12. mgeorgy@vmsclst1.sc.csupomona.edu writes:
  13.  
  14. >Hello, the program that follows began as a simple imaging program that I was
  15. >writing for myself.  But now it has become a big problem.  Everything ok except
  16. >the file opening and creating.  When I run the program and select option 1 or
  17. >2, open or create a file, I get a DEVICE ERROR.  I can tell you what is
  18. >happening but I just don't know why.  What is happening is that when it get to
  19. >the GET_LINE statment it uses IN_FILE_NAME's decleration of ' '.  Now I should
  20. >tell anyone willing to help me that the statments work alone but not as part of
  21. >another program (ie, IF statment, or sub-PROCEDURES).  I have raked my brain
  22. >and tried everything.  
  23.  
  24. >SOMEONE PLEASE HELP ME!!!!!!
  25.  
  26. >THANX FOR ANY HELP,
  27. >Matt Georgy
  28. >California Polytechnic State University, Pomona  -- Computer Science
  29.  
  30. >+++++++++++++++++++++++++++++++++++++++++++++++++++++++
  31. >+  Cal Poly, Pomona, Making Yesterdays Mistakes Today +
  32. >+++++++++++++++++++++++++++++++++++++++++++++++++++++++
  33.  
  34.  
  35.  
  36. Often when using the Text_IO.Get_Line routine this problem occurs.
  37.  
  38. The Get_Line routine looks for a <CR> on the input buffer to terminate
  39. the input stream.  In your case,  The previous 'Get' ignores the <CR>
  40. and most likely leaves it in the input buffer.  So, Along comes your
  41. Get_Line and 'Holy Cow'... There is a <CR> sitting in the input buffer,
  42. probably the first byte, and since there is a <CR> you must have
  43. completed your input... Get_Line OVER ....  a string of length ZERO(0)
  44. has entered.
  45.  
  46. If you look at the value of INPUT_LINE_LENGTH or OUTPUT_LINE_LENGTH 
  47. after you execute the Get_Line and prior to your attempt at opening
  48. a file..... You'll probably find that it contains the value ZERO(0).
  49.  
  50.  
  51. To fix this problem:  Try using the Text_IO.Skip_Line routine, which 
  52. skips over the next <CR>.  The proper location for the Skip_Line is 
  53. just prior to the Get_Line and AFTER the Get.   You'll need one 
  54. Skip_Line before each of your Get_Line calls.  
  55.  
  56. Look at the calls below.. Try them .. and let me know if it works ...
  57. It Should solve your problem.
  58.  
  59.                                 Don Princiotta
  60.                                 dep@swlra1.msd.ray.com
  61. ~
  62.  
  63.  
  64.  
  65. >P.S. Please reply by posting to the news group our mail system is screwed up
  66. >right now.
  67.  
  68. >THANX AGAIN.
  69.  
  70. >-------------------------------------------------------------------------------
  71. >with TEXT_IO, INTEGER_TEXT_IO, SEQUENTIAL_IO;
  72. >use TEXT_IO, INTEGER_TEXT_IO;
  73.  
  74. >procedure IMAGE is
  75. >   
  76. >type BYTE is range 0..255;
  77. >for BYTE'size use 8;
  78.  
  79. >package BYTE_IO is new SEQUENTIAL_IO(BYTE);
  80. >use BYTE_IO;
  81.  
  82. >   type BYTE_STRING is ARRAY (1..512) of BYTE;
  83.  
  84. >   INF                  :  BYTE_IO.FILE_TYPE;
  85. >   IN_FILE_NAME         :  STRING (1..80) := (others => ' ');
  86. >   INPUT_LINE_LENGTH    :  INTEGER := 0;
  87. >   IN_FILE_OPEN         :  BOOLEAN := FALSE;
  88. >   
  89. >   OUTF                 :  BYTE_IO.FILE_TYPE;
  90. >   OUT_FILE_NAME        :  STRING (1..80) := (others => ' ');
  91. >   OUTPUT_LINE_LENGTH   :  INTEGER := 0;
  92. >   OUT_FILE_OPEN        :  BOOLEAN := FALSE;
  93. >   
  94. >   READ_BYTE            :  BYTE;
  95. >   READ_STRING          :  BYTE_STRING;
  96. >   COUNTER              :  INTEGER := 0;   
  97. >   SELECTION            :  INTEGER := 1;
  98. >   
  99. >   procedure IMAGING_MENU is
  100. >   
  101. >   begin
  102. >   
  103. >      NULL;
  104. >      
  105. >   end IMAGING_MENU;
  106. >   
  107. >begin
  108.  
  109. >   while SELECTION /= 0 loop    
  110. >        PUT("STATUS:     INPUT FILE: ");
  111. >      if IN_FILE_NAME(1) = ' ' then
  112. >         PUT("<NONE>");
  113. >      else
  114. >         PUT(IN_FILE_NAME);
  115. >         IN_FILE_OPEN := TRUE;
  116. >      end if;
  117. >         PUT("        ");
  118. >      PUT("   OUTPUT FILE: ");
  119. >      if OUT_FILE_NAME(1) = ' ' then
  120. >         PUT("<NONE>");
  121. >      else
  122. >         PUT(OUT_FILE_NAME);
  123. >         OUT_FILE_OPEN := TRUE;
  124. >         end if;
  125. >      NEW_LINE(2);
  126. >      PUT("          Welcome to POLY-Vision");
  127. >      NEW_LINE(3);
  128. >      PUT_LINE("                 MAIN MENU");
  129. >      NEW_LINE;
  130. >      PUT_LINE("          (1) Get Input Filename");
  131. >      NEW_LINE;
  132. >      PUT_LINE("          (2) Get Output Filename");
  133. >      NEW_LINE;
  134. >         PUT_LINE("          (3) Begin Image Processing");
  135. >      NEW_LINE;
  136. >      PUT_LINE("          (0) Exit POLY-Vision");
  137. >      NEW_LINE(2);
  138. >      PUT_LINE("                   CHOICE: ");
  139. >      GET(SELECTION);
  140.           -- <CR> left on the input buffer....
  141. >      if SELECTION = 1 then
  142. >            PUT_LINE("INPUT FILE NAME: ");
  143.  
  144.  
  145.              -- Insert call to remove <CR> fromthe input buffer....
  146.              Text_IO.Skip_Line;
  147.  
  148.  
  149. >            GET_LINE(IN_FILE_NAME, INPUT_LINE_LENGTH);
  150. >         open(INF, IN_FILE, IN_FILE_NAME(1..INPUT_LINE_LENGTH));
  151. >      elsif SELECTION = 2 then
  152. >            PUT("OUTPUT FILE NAME: ( ");
  153. >            PUT(IN_FILE_NAME(1..INPUT_LINE_LENGTH - 3));
  154. >            PUT_LINE("NEW )");
  155.  
  156.  
  157.              -- Insert call to remove <CR> fromthe input buffer....
  158.              Text_IO.Skip_Line;
  159.  
  160.  
  161. >            GET_LINE(OUT_FILE_NAME, OUTPUT_LINE_LENGTH);
  162. >            if OUT_FILE_NAME(1) = ' ' then
  163. >               create(OUTF, OUT_FILE, IN_FILE_NAME(1..INPUT_LINE_LENGTH - 3) & "NEW");
  164. >            else
  165. >               create(OUTF, OUT_FILE, OUT_FILE_NAME(1..OUTPUT_LINE_LENGTH));
  166. >            end if; 
  167. >      elsif SELECTION = 3 then
  168. >         IMAGING_MENU;
  169. >      else
  170. >         if IN_FILE_OPEN then
  171. >            close(INF);
  172. >            end if;
  173. >         if OUT_FILE_OPEN then
  174. >            close(OUTF);
  175. >         end if;
  176. >         EXIT;
  177. >      end if;
  178. >   end loop;
  179. >end IMAGE;
  180.  
  181.  
  182. P.S.
  183.  
  184. Over use of the Skip_Line will result in your program waiting
  185. for you to hit the <CR> when you really didn't want that to 
  186. happen.  Be careful when using it and GOOD LUCK.
  187.  
  188. --- END OF MESSAGE ---
  189.