Board index » delphi » Need help with a pascal function

Need help with a pascal function

Hi , I`m a correspondence CS student and I need to write a program
which reads integers out of a txt file using the "Val" function. My
problem is that my books don`t give me any detail about standard
functions.  Could anybody post a brief explanation about  how and what
this function does?
                                                                                                                        Thanks in advance. LB

 

Re:Need help with a pascal function


Quote
> Hi , I`m a correspondence CS student and I need to write a program
> which reads integers out of a txt file using the "Val" function. My
> problem is that my books don`t give me any detail about standard
> functions.  Could anybody post a brief explanation about  how and what
> this function does?

   It converts a string of numeric characters (0..9) to the targetted
numeric data type, according to the Pascal rules of data.  Thus, a
string S containing "   2310" can be converted to its integer equivalent
N by:
  Val (S,N,I)
where S is that string, N is an integer variable, and I is an integer
variable which will contains the position of the illegal character in
the string if the action fails - if I > 0, the Val didn't work, and I
points to the character in the string where the failure occured.
   BTW, the online Help which comes with TP/BP should provide this sort
of information - just type "Val" into a program and press Ctrl-F1 at its
location on the screen.

Re:Need help with a pascal function


Hello LB!

Answering a message from 01.04.97 04.29.06 from LB to All:

 L> From: l...@ix.netcom.com (LB)

 L> Hi , I`m a correspondence CS student and I need to write a program
 L> which reads integers out of a txt file using the "Val" function. My
 L> problem is that my books don`t give me any detail about standard
 L> functions.  Could anybody post a brief explanation about  how and what
 L> this function does?                Thanks in advance. LB

My Borland-Pascal 7.0 Online Help ( German version ) says :

val   :

 Val (Prozedur)
 ###############
Interpretiert einen String als numerischen
Wert.

 Deklaration:
 procedure Val(S; var V; var Code: Integer);
 Es gilt:
  S          ist eine Variable des Typs String, die eine Zeichenfolge
             speichert, die einen numerischen Wert (mit Vorzeichen) ergibt.
  V          ist eine Variable mit einem Integer- oder Real-Typ.
  Code       ist eine Variable des Typs Integer.

 Zielsystem:
Windows, Real, Protected

 Bemerkungen:
Konvertiert den Wert des String (S) in seine
numerische Entsprechung, so als ob dieser
String mittels Read aus einer Textdatei
gelesen wuerde.

 Siehe auch:
  Str

 Beispielprogramm:

   {Val.PAS}

  {Beispielcode fuer die Prozedur Val }

  var I, Code: Integer;
  begin
  { Get text from command line }
    Val(ParamStr(1), I, Code);
    { Error during cnversion to integer? }
    if code <> 0 then
      Writeln('Error at positon: ', Code)
    else
      Writeln('Value = ', I);
  end.

Servus, Gottfried!
( Gottfried.Gid...@itc.or.at )

Re:Need help with a pascal function


Re:Need help with a pascal function


Quote
On Tue, 01 Apr 1997 02:29:13 GMT, l...@ix.netcom.com (LB) wrote:
>Hi , I`m a correspondence CS ....

        The correct Email address for LB is si...@iquest.net .
    l...@ix.netcom.com is not valid anymore (I have a new ISP),

     thanks again for your time.

                                                                                                                                                        Luis Berenguer.

Re:Need help with a pascal function


Re:Need help with a pascal function


LB <l...@ix.netcom.com> wrote in article
<334052d9.4104...@news.supernews.com>...

Quote
> Hi , I`m a correspondence CS student and I need to write a program
> which reads integers out of a txt file using the "Val" function. My
> problem is that my books don`t give me any detail about standard
> functions.  Could anybody post a brief explanation about  how and what
> this function does?
>                                                                                                                    Thanks in advance. LB

Val converts a string value to its numeric representation.

 Declaration:  procedure Val(S; var V; var Code: Integer);
  S     string-type variable
  V     integer-type or real-type variable
  Code  variable of type Integer.

Converts the string value (S) to its numeric representation, as if it were
read from a text file with Read.

--
----------------------------------------------------------------------------
----
?                    mail to : mre...@ici.net                      ?
?  http://www.ici.net/cust_pages/mrealm/BANDP.HTM ?
----------------------------------------------------------------------------
-----
' It is better to die on your feet, than to live on your knees! '

Re:Need help with a pascal function


  The use of Val procedure is:
        " Val(s,n,error) "
   where:
        s is a string when you obtain your number as a string.
        n is the integer or real number you want to convert to a string.
        error is one integer where the procedure reports you  the possible
errors in operation. If error is 0 the operation is ok.

        From Spain:    
                                Medulius.
                        Vivan os martires do Medulio.

Quote
On Tue, 1 Apr 1997, LB wrote:
> Hi , I`m a correspondence CS student and I need to write a program
> which reads integers out of a txt file using the "Val" function. My
> problem is that my books don`t give me any detail about standard
> functions.  Could anybody post a brief explanation about  how and what
> this function does?
>                                                                                                                    Thanks in advance. LB

Other Threads