Previous: 4.67.2.92. UpCase function To the Table of Contents Next: 4.67.2.94. Win32BuildNumber function
4.67.2.92. UpCase function Table of Contents 4.67.2.94. Win32BuildNumber function

- 4.67.2.93. -
Table of Contents
4. Standard Units
4.67. System - Built-in routines
4.67.2. System Unit Procedures and Functions
4.67.2.93. Val procedure


4.67.2.93. Val procedure

Targets: MS-DOS, OS/2, Win32


System Unit

Converts a string value to its numeric representation.

Declaration:
procedure Val(S; var Value; var Code: Integer);
Remarks:
S is of string type. Value is an integer or real type variable. Code returns an integer value indicating whether the operation was successful or where it failed.

S is a string of numeric characters. Val attempts to convert S to a valid integer or real types number. If successful, Code returns zero, otherwise Code returns the index in S where the conversion failed.

Example:
{$ifndef __CON__}
  This program must be compiled as console application only
{$endif}
uses Strings;
var
  Num: String;
  Code: Longint;
  Value: Extended;
begin
  Write('Enter a number: ');
  ReadLn(Num);
  Val(Num, Value, Code);
  if Code <> 0 then
    Writeln('Error at position: ', Code)
  else
    Writeln('(Value * 2) = ', Fls(Value * 2));
end.
See also:
Str


Previous: 4.67.2.92. UpCase function To the Table of Contents Next: 4.67.2.94. Win32BuildNumber function
4.67.2.92. UpCase function Table of Contents 4.67.2.94. Win32BuildNumber function

- 4.67.2.93. -