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,609 of 2,978   
   John Smith to All   
   Re: Getting a real number from the keybo   
   26 May 05 13:28:40   
   
   From: assemblywizard@gmail.com   
      
   Jim:   
      
   That worked great, and if I use "readln(s)" val(s, r, i) works!!!   
      
   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--and is there a way I can   
   "transform" the string read one char at a time, with readkey, to where it   
   can be used with val?   
      
   Warmest regards,   
   John   
      
   "Jim Leonard"  wrote in message   
   news:1117138099.252081.245570@z14g2000cwz.googlegroups.com...   
   > John Smith wrote:   
   >> I have tried the following:   
   >> {$N+}{$X+}   
   >> ch: char;   
   >> i: integer;   
   >> s: array[0..80] of char;   
   >> r: extended;   
   >> BEGIN   
   >>    while ctr <> #13 do   
   >>       BEGIN   
   >>          ch := getkey;   
   >>          s[ctr] := ch;   
   >>          inc(ctr);   
   >>      END;   
   >>       val(s, r, ctr);   
   >>       writeln('r = ', r:8:8);   
   >> END;   
   >>   
   >> It doesn't work, what am I doing wrong?   
   >   
   > A lot :-)  Instead, try this:   
   >   
   >    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:=getkey;   
   >      s:=s+ch;   
   >    END;   
   >    dec(s[0]); {"deletes" the #13 (CR) and the end by decreasing string   
   > length}   
   >   
   > That will progressivly fill up string "s" with each character.  You can   
   > get the length of the string with s[0] (the first byte is the length of   
   > the string).   
   >   
   > However, it is much easier to replace ALL of that with simply one   
   > statement:   
   >   
   >    readln(s);   
   >   
   > As for the rest, I have no idea what you're trying to do with:   
   >   
   >    val(s, r, ctr);   
   >    writeln('r = ', r:8:8);   
   >   
   > ...maybe you can explain what your goal is?   
   >   
      
   --- 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