Previous: UpCase function To the Table of Content Next: Win32BuildNumber function

- 4.62.2.93 -
Standard Units
System Unit
System Unit Procedures and Functions

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: UpCase function To the Table of Content Next: Win32BuildNumber function
UpCase function Table of Content Win32BuildNumber function

- 4.62.2.93 -