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,678 of 2,978   
   Jim Higgins to assemblywizard@gmail.com   
   Re: Getting a real number from the keybo   
   29 May 05 23:10:49   
   
   From: me7@privacy.net   
      
   On Sun, 29 May 2005 13:21:03 -0700, in   
   , "John Smith"   
    wrote:   
      
   >Wow!   
   >Just downloaded and played with FPC (free pascal compiler 2.0.0)...   
   >... wonderful, has no problems with anything... for example...   
   >program test;   
   >   
   >{E-}{$X+}   
   >   
   >USES Crt, Strings;   
   >   
   >VAR   
   >   a:   array[0..80] of char;  { as null string compatable array }   
   >   s:   string;   
   >   ch:  Char;   
   >   ctr: Integer;   
   >   r:   real;   
   >   
   >BEGIN   
   >   ctr := 0;   
   >   writeln('ctr start = ', ctr);   
   >   while ch <> #13 do   
   >      BEGIN   
   >         ch := readkey;   
   >         if (((byte(ch) <= 57) AND (byte(ch) >= 48)) OR   
   >            (byte(ch) = 45) OR (byte(ch) = 46)) then   
      
   OK, but for a more easily readable alternative you might consider   
   the utility of sets...   
      
   	if byte(ch) in [45, 46, 48..57] then   
      
   >            BEGIN   
   >               write(ch);   
   >               a[ctr] := ch;   
   >               ctr := ctr + 1;   
   >            END   
   >         else   
   >            if ch = #8 then   
   >               BEGIN   
   >                  write(#8, ' ', #8);   
   >                  ctr := ctr - 1;   
   >            END;   
   >      END;   
   >   writeln;   
   >   val(a, r, ctr);   
      
      
   Ouch!  You just reused the global variable (ctr) used to keep   
   track of the length of your input array.  Does the shop you work   
   in tolerate that practice?   
      
      
   >   writeln('r = ', r:8:8);   
   >   s := StrPas(a);   
   >   val(s, r, ctr);   
   >   writeln('second r = ', r:8:8);   
   >{X-}   
   >END.   
      
   Looks like you're getting the hand of it.   
      
   --- 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