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,645 of 2,978   
   John Smith to All   
   Re: Getting a real number from the keybo   
   27 May 05 18:20:37   
   
   From: assemblywizard@gmail.com   
      
   you apparently don't understand the difference between pascal and null   
   terminated strings--NO one would use a pascal string--it is pascal specific   
   and can't be ported or code built into a .dll which can be called from other   
   languages...   
      
   forget it, you all have worn me out--the answer still is, "IT DOESN"T   
   WORK--AND FOR THE LIFE OF ME I DON"T KNOW WHY YOU CANNOT SEE THAT   
   YOURSELVES!!!"   
      
   are you all high, are you all children, what the hell has happened to   
   newsgroups?   
      
   Warmest regards,   
   John   
      
   "F Verbeek"  wrote in message   
   news:119fgrqce3q8h9b@corp.supernews.com...   
   > In the obscure news:iQIle.21$TJ7.1239109@news.sisna.com,   
   > Someone calling himself John Smith   
   > suspiciously hiding as  uttered:   
   >> OK, let me explain more.  I have no problem building a string, if   
   >> that is ALL I want--a character at a time...  the object is to come   
   >> with with a WHOLE string of character digits--INCLUDING decimal   
   >> point--which can be converted into a REAL--EXTENDED or COMP type I   
   >> CAN do math with... I know how to program in assembly, C, C++,   
   >> fortran, pascal, basic, cobol... I DON'T NEED HELP IN PROGRAMMING   
   >> SYNTAX--some of the examples are pseudocode I give--I figure everyone   
   >> here CAN program and needs no help in that--I have been away from   
   >> pascal for years and just need to make a small program work--for   
   >> example, the following WORKS and demonstartes how I want to use VAL   
   >> on a string--this is ONLY for demononstration: {* pseudocode begins *}   
   >> var   
   >>    s: string;   
   >>    r, r2: real;   
   >>    i: integer;   
   >>    s := '123.456';   
   >>    val(s, r, i);   
   >>    r2 := r * 99;   
   >>    writeln('r2 = ', r2:8:4);   
   >> {* pseudocode ends*}   
   >>   
   >> This works also, and is ONLY for demonstration:   
   >> {* code begins *}   
   >> var   
   >>    s: string;   
   >>    r, r1: real;   
   >>    i: integer;   
   >>    readln(s);   
   >>    val(s, r, i);   
   >>    r1 := r * 99;   
   >>    writeln('r1 = ', r1:8:4);   
   >> {* code ends *}   
   >>   
   >> THIS DOES NOT WORK (although it DOES RUN--but VAL fails on the string   
   >> constructed), and IS what I want to do, AND the ONLY thing I AM   
   >> concerned about is making VAL work on the string--the syntax I can   
   >> handle...: {* CODE BEGINS *}   
   >> PROGRAM MREAL;   
   >>   
   >> USES crt;   
   >>   
   >> VAR   
   >>    s: STRING;   
   >>    r, rr: REAL;   
   >>    ctr: INTEGER;   
   >>    ch: CHAR;   
   >>   
   >> PROCEDURE makereal;   
   >> BEGIN   
   >>    ch := ' '; { just give it something that won't stop the loop }   
   >>    ctr := 0;   
   >>    while ch <> #13 do   
   >>       BEGIN   
   >>          ch := ReadKey;   
   >>          write(ch);   
   >>          s[ctr] := ch;   
   >>          ctr := ctr + 1;   
   >>        END;   
   >>    VAL(s, r, ctr);   
   >>     rr := r * 99;   
   >>    writeln;   
   >>    writeln('rr = ', rr:8:4);   
   >> END;   
   >>   
   >> BEGIN   
   >>    ClrScr;   
   >>    makereal;   
   >> END.   
   >> {* CODE ENDS *}   
   >>   
   >> If that cannot be understiood... I just don't know what to say... I   
   >> am out of words and amazed...   
   >>   
   >> Warmest regards,   
   >> John   
   >>   
   >   
   > If you are a programmer of that experience you should have known that the   
   > first thing to do is to look up the specific behavior of all types and   
   > functions you are using. Apparently you are in lack of some basic   
   > knowledge here.   
   >   
   > A char is a single byte containing a value in the range of <0..255>. The   
   > behavior of the char in a program is that of a letter. e.g. it is   
   > perfectly legal to put   
   > ch:='A';   
   > Meaning that ch will behave as the letter A but actually you've stored a   
   > value of 65, the corresponding ascii value in ch.   
   > The way to get the stored (ordinal) value is by putting ORD(ch).   
   > Putting   
   > ch:=#65;   
   > write(ch);   
   > will yield you an 'A' on the screen   
   > The same for ch:=str(65)   
   >   
   > The standard string type in TP is stored as follows:   
   > A string is an array [0..255] of char;   
   > The length of the data contained in the string is stored in the first   
   > char.   
   > So LENGTH (s) is equivalent to ORD(S[0])   
   > If the string contains no data, S[0] equals #0.   
   > The first character in the string is stored in S[1] and the last one in   
   > S[ORD(S[0])]   
   > A string can contain a maximum of 255 chars.   
   > If you want longer strings, you must use null terminated strings, which is   
   > also possible in TP V7, but they are handled in a completely different   
   > way.   
   >   
   > In your constructing of the string, you forget to set the correct length   
   > of the string by storing that in S[0] You stored the first keyboard   
   > character in S[0] instead of in S[1].   
   > Further you did not even take notice of the correct use of the VAL   
   > procedure. You are passing the control parameter, used for counting it   
   > keyboard inputs, as success return value, loosing it's former information   
   > and you are not using it's new information. Look again at what I wrote   
   >   
   > val(s,r,code);   
   >  if code<>0 then writeln(' error')   
   >                     else writeln(r);   
   >   
   > So if the call to VAL fails to return a number, the value stored in code   
   > will be non zero.   
   >   
   >   
   > --   
   > Femme Verbeek   
   >   
   >   
      
   --- 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