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,641 of 2,978   
   John Smith to All   
   Re: Getting a real number from the keybo   
   27 May 05 18:05:40   
   
   From: assemblywizard@gmail.com   
      
   How old are you?   
      
   John   
      
   "Jim Leonard"  wrote in message   
   news:1117239768.547085.221490@g14g2000cwa.googlegroups.com...   
   > John Smith wrote:   
   >> LOL... you havent a clue...   
   >   
   > No, sir, it is you who doesn't have the first clue that *pissing off   
   > the people that you need help from* is not the smartest idea in the   
   > world.   
   >   
   > I need to fill up my karma jar a little, so guess what, asshat?  You   
   > get your code.  I have added more comments than actual code so that you   
   > can LEARN SOMETHING.   
   >   
   > {$E+,N+}   
   > Program validnum;   
   > {   
   > Validates a fractional number as it is being input.  Created in   
   > response to a fairly rude individual on comp.lang.pascal.borland.  To   
   > that person:  Lighten up.  Life's too short to go pissing off everyone   
   > you need help from.   
   >   
   > There are many different ways to skin a cat...  This is my version,   
   > which uses some Turbo/Borland Pascal features (like pascal-style   
   > strings and typecasting) that may not be availble on other pascal   
   > compilers.   
   >   
   > To test error handling, try entering a number with more than one minus   
   > sign or period.  The exact location of the error during conversion will   
   > be displayed. It is left as an exercise to the reader to detect for   
   > this condition during input so that there cannot be an error at all.   
   > }   
   >   
   > uses   
   >  crt; {for the "readkey" function and sound routines}   
   >   
   > var   
   >  e:extended; {the real number we will be converting to}   
   >  ch:char; {somewhere to hold the character}   
   >  s:string[20]; {the string used to build the text representation of   
   > the real number}   
   >  errcode:integer; {error code, if any, from the val() conversion}   
   >   
   > begin   
   >  s:=''; {Initialize our string to equal nothing}   
   >  writeln('Input a fractional number.  Valid keys are "-", ".", ,   
   > and :');   
   >  repeat   
   >    ch:=readkey;   
   >    case ch of   
   >      '0'..'9','.','-':begin {if a number, period, or minus sign is   
   > input, add it to the string}   
   >        s:=s+ch; {add it to the string}   
   >        write(ch); {echo the character just input so the user can see   
   > what they're typing}   
   >      end;   
   >      #13:; {trap character but don't do anything else with it}   
   >      #8:if ( byte(s[0]) > 0 ) then begin   
   >        dec(byte(s[0])); {if the user hits backspace, and the string is   
   > not empty, decrease the length of the string by one.  The "byte()" cast   
   > forces pascal to treat s[0] as a byte, not a character.  The [0] is the   
   > not the first character of the string, but actually a value   
   > representing the total length of the string.}   
   >        write(ch,' ',ch); {move back, erase the last onscreen   
   > character, move back}   
   >      end;   
   >    else {not a valid character}   
   >      begin   
   >        sound(100); {make a little "burp" sound so the user knows they   
   > hit an invalid key}   
   >        delay(100);   
   >        nosound;   
   >      end;   
   >    end; {case}   
   >  until (ch=#13) or ( byte(s[0]) = sizeof(s)-1 ); {exit if enter   
   > pressed, or we're at the maximum length of the string}   
   >  writeln; {advance to next line}   
   >  val(s,e,errcode); {convert string 's' into extended 'e' with error   
   > code 'errcode'}   
   >  if (errcode=0) {if no error, print number, else print what's wrong   
   > with the number}   
   >    then writeln('You input the number: ',e:8:8)   
   >    else begin   
   >      writeln('There was an error converting the string at this   
   > position:');   
   >      writeln('"',s,'"');   
   >      writeln(#32:errcode,'^');   
   >    end;   
   > end.   
   >   
      
   --- 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