next up previous contents index
Next: Write Up: Functions and Procedures Previous: Upcase

Val

   

Declaration:

Procedure Val (const S : string;var V;var Code : word) ;

Description:

Val converts the value represented in the string S to a numerical value, and stores this value in the variable V, which can be of type Longint, real and Byte.

If the conversion isn't succesfull, then the parameter Code contains the index of the character in S which prevented the conversion.

The string S isn't allow to contain spaces.

Errors:

If the conversion doesn't succeed, the value of Code indicates the position where the conversion went wrong.

See also:

Str

Example
Program Example74;

{ Program to demonstrate the Val function. }
Var I, Code : Integer;

begin
  Val (ParamStr (1),I,Code);
  If Code<>0 then 
    Writeln ('Error at position ',code,' : ',Paramstr(1)[Code])
  else
    Writeln ('Value : ',I);  
end.



Michael Van Canneyt
Thu Sep 10 14:02:43 CEST 1998