I am assuming you want to use the val procedure that is part of unit system, see
hereA variable parameter is a parameter that is (also) returned by a procedure or function. Also see
here.
So, in contrary to your ordinary function that is only able to return a single return value, you can use var parameters to return a multiple amount of return values.
For that to work, you need to pass the correct variables (type) to the function or procedure.
In the case of procedure val:
- 1st parameter: const S: string;
- 2nd parameter: var V; (note that this variable is untyped)
- 3th parameter: var Code: Word
So, the first parameter is to be a string (string notation of a number).
The second parameter is an untyped variable but, the documentation writes about restrictions:
... variable V, which can be of type Longint, Real and Byte or any enumerated type.
And the last parameter should be a word.
Therefor, the correct call would be:
var
vec:string; // note, that is variable is a string
StringAsInteger: Integer; // note, that this is an integer.
ErrorCode : Word;
begin
writeln('Write only a number');
// let user enter a string
// (not an integer, in opposite to your example that directly tries to read the input into an integer variable)
readln(vec);
// try to convert the string into a integer number, from var vec to var StringAsInteger
val(vec,StringAsInteger,ErrorCode);
end.
You can then check the returned ErrorCode to see if the 'conversion' from string to integer went ok.
edit: typo's + some additional comments