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,637 of 2,978   
   Jason Burgon to John Smith   
   Re: Getting a real number from the keybo   
   27 May 05 22:59:45   
   
   From: gvision@ntlworld.com   
      
   "John Smith"  wrote in message   
   news:7VIle.22$9u.1280150@news.sisna.com...   
   > Jason:   
   >   
   > See a post of mine above, which gives an actual program/procedure which   
   > fails--I don't need help in syntax   
      
   Clearly you do. Everyone in this ng knows it except you.   
      
   > --I don't need help building a string one character at a time   
      
   I didn't offer any. I mistakenly thought that some things were too trivial   
   even for programming newbies like yourself.   
      
   > --all I need is for val to work on a string which has been build one   
   character at a   
   > time...   
      
   No you don't, you need help in understanding Pascal syntax and the structure   
   of a TP/BP style Pascal string, which you have been given, but have chosen   
   to ignore.   
      
   > I KNOW PASCAL SYNTAX!!!   
      
   Jim, many people here have tried to help you, and all we get for our   
   trouible is you going off on one. Here in c.l.p.b we usually avoid writing   
   the code ourselves because it rarely provides the best way for the student   
   to gain understanding. Despite that, I see that at least one person has   
   written a fully working example, and all you do is SHOUT at him.   
      
   Right, I'm in a good mood so here come the idiots guide to building a   
   string, one character at a time from the keyboard:   
      
   (1) Declare your working varibles:   
      
   function KbdGetString: string;   
   var   
     S: string;   
      
   (2) Inialize all your variables ~before~ you use them:   
      
   begin   
     S := ''; { S is now a null string. Btw, that's two single quotes,   
   semicolon}   
      
   (3) Place a "readkey" inside a loop that checks for your "end-of-input"   
   character, construct your string by appending the each i/p character to the   
   end of it:   
      
     repeat   
       S := S + ReadKey;   
       Write(S[Length(S)]);    { For user-feedback }   
     until S[Length(S)] = #13;   
     Write(#10); { DOS uses CR+LF for end-of-line }   
      
   (4) Remove the "end-of-input" character from the string:   
      
     Delete(S, Length(S), 1);   
      
   (5) Return the function result - a string suitable for Val if all it   
   contains is decimal digits and no more than one full-stop.   
      
     KbdGetString := S;   
   end;   
      
   (6) Write a test program:   
      
   program TstStrIP;   
      
   uses Crt;   
   var   
     S: string;   
   begin   
     Write('Type a string - ');   
     S := KbdGetString;   
     WriteLn('The string entered from the keyboard was "', S, '"');   
   end.   
      
   The above function is of course very crude. It does not allow any editing of   
   the string for example. I'll leave that as an exercise for your good self.   
      
   --   
   Jay   
      
   Author of Graphic Vision   
   http://homepage.ntlworld.com/gvision/   
      
   --- 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