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,630 of 2,978   
   John Smith to All   
   Re: Getting a real number from the keybo   
   27 May 05 14:24:29   
   
   From: assemblywizard@gmail.com   
      
   Never mind bonehead:   
   I have written a program which demonstartes ALL three--null string   
   array--pascal string--and a "real" string...   
   ... this DOES COMPILE--this DOES RUN...   
   NONE OF THE METHODS WORK and the real is always returned from val as ZERO!   
   Simply change this so one of the methods work, and the real is returned...   
   by reading in the character ONE CHAR at a time...   
   --RUN IT BEFORE YOU REPLY--   
   {******* CODE BEGINS ******}   
   program test;   
   {$X+}   
      
   USES Crt, Strings;   
      
   VAR   
      a:   array[0..80] of char;  { as null string compatable array }   
      b:   array[1..80] of char;  { as a Pascal String }   
      s:   string[80];            { as a string }   
      ch:  Char;   
      ctr: Integer;   
      r:   real;   
      
   BEGIN   
   { first demo as a null string compatable array }   
      ch := ' '; { give it something NOT a CR }   
      ctr := 0;  { null terminated string index }   
      while ch <> #13 do   
         begin   
            ch := readkey;   
            write(ch);   
            a[ctr] := ch;   
            inc(ctr);   
         end;   
      writeln;   
      writeln(a);   
      val(a, r, ctr);   
      writeln(r:8:8);   
      
   { second demo as a pascal string array }   
      ch := ' '; { give it something NOT a CR }   
      ctr := 1;  { Pascal string index }   
      while ch <> #13 do   
         begin   
            ch := readkey;   
            write(ch);   
            b[ctr] := ch;   
            inc(ctr);   
         end;   
      writeln;   
      writeln(b);   
      val(b, r, ctr);   
      writeln(r:8:8);   
      
   { third demo as a string }   
      ch := ' '; { give it something NOT a CR }   
      ctr := 1;  { Pascal string index }   
      while ch <> #13 do   
         begin   
            ch := readkey;   
            write(ch);   
            s[ctr] := ch;   
            inc(ctr);   
         end;   
      writeln;   
      writeln(s);   
      val(s, r, ctr);   
      writeln(r:8:8);   
   END.   
   {******* CODE ENDS *******}   
      
   John   
      
   "Jim Leonard"  wrote in message   
   news:1117225741.491422.70130@g49g2000cwa.googlegroups.com...   
   > John Smith wrote:   
   >> ... well, you have given methods... none of which work...   
   >>   
   >> ... forget giving me methods of getting a string one character at a   
   >> time...   
   >> after you use any method, take the string and run val on it and write out   
   >> the real--it WILL be zero!   
   >>   
   >> You seem to wish to teach me syntax... that is NOT what I am after...   
   >> and   
   >> here the matter hangs...   
   >   
   > Geezus H. Christ.  You want us to write the damn code for you?  Several   
   > times people have given you the information you need for you to WRITE   
   > IT YOURSELF, from fixing the string-building-by-character code you   
   > submitted, to explicitly stating that, yes, val() *is* the correct   
   > function to use to convert a string to a value.  You have the   
   > information you need!  Fix it!   
   >   
   > For the boneheaded:  Here is a recap of the information you need to fix   
   > it:   
   >   
   > - val() converts strings to real numbers.  It didn't work for you   
   > because you were passing it an ARRAY of CHARs, not a "string" variable.   
   > Yes, a string is technically an array of chars, but "string" is the   
   > proper variable type if you want to use TP/BP's internal string   
   > handling routines.   
   >   
   > - To append a character to a string, use the "+" operator, like this:   
   > MyString:=MyString+MyChar   
   >   
   > - You can initialize your string to equal nothing like this:   
   > MyString:=''   Do this before you start mucking with it, just to be   
   > safe.   
   >   
   > If you want 100% working compilable TP/BP 7.0 code to do exactly what   
   > you want, fine.  I will write it completely for you, complete with   
   > comments so you can understand it -- IF you publicly apologize to the   
   > group for being too ignorant to actually read the advice people have   
   > given you.   
   >   
      
   --- 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