top
Loading...
檢測整數和長整數的函數
經常見到cint和clng的溢出出錯,如果有檢測函數就不會出這個問題,下面這兩個函數是應朋友要求寫的,看一下吧

'檢測字符串是否是整數
function Is_Int(a_str)
if not isnumeric(a_str) or len(str) > 5 then
Is_Int = false
exit function
elseif len(str) < 5 then
Is_Int = true
exit function
end if
if cint(left(a_str , 4)) > 3276 then
Is_Int = false
exit function
elseif cint(left(a_str , 4)) = 3276 and cint(right(a_str , 1)) > 7 then
Is_Int = false
exit function
else
Is_Int = true
exit function
end if
end function

'檢測是否是長整數
function Is_Lng(a_str)
if not isnumeric(a_str) or len(str) > 10 then
Is_Lng = false
exit function
elseif len(str) < 10 then
Is_Lng = true
exit function
end if
if clng(left(a_str , 9)) > 214748367 then
Is_Lng = false
exit function
elseif clng(left(a_str , 9)) = 214748367 and clng(right(a_str , 1)) > 7 then
Is_Lng = false
exit function
else
Is_Lng = true
exit function
end if
end function

北斗有巢氏 有巢氏北斗