home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.pascal.borland      Borland Pascal was actually pretty neat      2,978 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 1,611 of 2,978   
   John Smith to John Smith   
   Re: Getting a real number from the keybo   
   26 May 05 14:54:10   
   
   From: assemblywizard@gmail.com   
      
   Or, in other words, this DOES NOT work:   
   PROGRAM T;   
      
   uses crt, strings;   
      
   var   
      ch: char;   
      s: string;   
      r: real;   
      i: integer;   
      
   begin   
      ch:=#0; {just in case you were previously using it}   
      s[0]:=#0; {set string length to 0 characters}   
      while ch <> #13 do   
         BEGIN   
            ch:=ReadKey;   
            s:=s+ch;   
         END;   
      dec(s[0]);   
      {"deletes" the #13 (CR) and the end by decreasing string length}   
      val(s, r, i);   
      writeln('r = ', r:8:8);   
   end.   
      
   THIS WORKS:   
   VAR s: string;   
            r: real;   
            i: integer;   
   readln(s);   
   val(s, r, i);   
   writeln('r = ', r:8:8);   
      
   Now, how can I do that while reading ONE character at a time?   
      
   Warmest regards,   
   John   
      
   "John Smith"  wrote in message   
   news:ndrle.147$KW.6024280@news.sisna.com...   
   > no, the question is how can I do it, reading one key at a time and   
   > converting that string read so it can be used with val...   
   >   
   > the question is NOT how to I use readln...   
   >   
   > Regards,   
   > John   
   >   
   > "Jim Leonard"  wrote in message   
   > news:1117142777.937388.45960@g49g2000cwa.googlegroups.com...   
   >> John Smith wrote:   
   >>> So, my question is, why if I use readln will val work... and NOT when I   
   >>> grab   
   >>> the string one char at a time with readkey--   
   >>   
   >> Because you weren't grabbing the string right.  See what I previously   
   >> wrote for fixed code.   
   >>   
   >   
   >   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca