Please enable JavaScript to view this site.


int = StrToIntDef(sString, nDefaultVal)


This macro function converts the string sString into a number, in the same manner as does the function IntToStr but, if the value of sString does not represent a valid number, then instead of generating an error, the function will return the value nDefaultVal.

// same behaviour as StrToInt()
StrToIntDef('1024', -1// 1024
StrToIntDef('0012', -1// 12
// the following would generate an error if used with StrToInt()
StrToIntDef('1.024', -1// -1 
StrToIntDef('1,024'12// 12
StrToIntDef('Elvis'666// 666

See also: StrToInt, IntToStr.


Topic 178795, last updated on 18-Apr-2020