qp.hlp (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
Val Procedure
  Summary Details Example                                   Back
 
  Arguments
 
    source    String representation of the number to be converted
 
    number    Receives the converted value
 
    code      Index of the first invalid character, or zero if none
 
  Description
 
    The Val procedure takes a string input and puts the real or integer
    number value of the string into a real or integer variable. Val
    also sets an error variable.
 
    The source argument contains a string that follows the syntax for
    an integer or real number. An integer can be in signed or unsigned
    decimal or hexadecimal notation. A real number can be expressed in
    scientific (engineering) notation or in ordinary decimal notation,
    with or without a fractional part.
 
    The syntax for an integer is
 
       [{+│-}] { <decimal digits> │ $<hexadecimal digits> }
 
    The syntax for a real number is
 
       [{+│-}] <digits> [.<digits>] [ {E│e} [+│-] <digits> ]
 
    The source may contain leading spaces but must not contain trailing
    spaces.
 
    Val sets code to 0 if successful. If the string does not represent
    a valid syntax for a number, Val sets code to the position in the
    string of the first invalid character.
 
    If the resulting value is out of range for the type of the number
    variable, the range checking state determines the outcome:
 
        When range checking is turned on with {$R+}, the program
        terminates, generating a run-time error message.
 
        When range checking is turned off with {$R-}, the result
        depends on the type of the number argument. A Real or LongInt
        contains an undefined result, and Val sets code to a nonzero
        value. Any other numeric type of number argument contains an
        overflow result, and Val sets code to zero.
 
    Use Val to convert numeric input from the command line or the
    keyboard to an integer or real value to be used in the program.
 
    The Str procedure acts as the inverse of Val, converting a number
    to a string representation.