View Full Version : "not valid integer value"
Hi there.. I have a quite basic problem here which I can't find the answare to since I don't know exactly what I'm looking for.. I want to check if a string is a valid integer value before doing an StrToInt(); to avoid the "not valid int value" error message. I tried adding try, except, finally, but that diddn't remove the message..
Alimonster
17-06-2004, 04:39 PM
StrToIntDef tries to convert the string, and gives you back a default value if it can't convert. For example, to convert, and get back -1 if a problem occurs:
MyInt := StrToIntDef(YourString, -1);
Alternatively, use exception handling:
try
MyInt := StrToInt(YourString);
except
// a problem occurred - deal with it
MyInt := -1;
end;
cairnswm
18-06-2004, 04:30 AM
The Val function turns a string into an integer but allows an error code as a third parameter that indicates the first character in the string that isn;t numeric.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.