首先我們需要了解的是
cint範圍-32,768 到32,767。
clng範圍-2,147,483,648 到2,147,483,647。
cint與clng含義:
都可以強制將一個表達式轉換成數據類型
cint與clng處理數據的範圍:
CInt Integer -32,768 至32,767,小數部分四捨五入。
CLng Long -2,147,483,648 至2,147,483,647,小數部分四捨五入。
所謂溢出指的是超出處理數據的範圍,下面代碼是處理數據防止溢出的代碼,大家可以自己看看:
'檢測是否是短整數
複製代碼代碼如下:
sub Is_Int(string)
if len(abs(string))>10 then response.write "數據溢出":response.end
if instr(string,"-")<1 then
if cint(left(string,4))>3276 and cint(right(string,1))>7 then response.write "數據溢出":response.end
else
if cint(left(abs(string),4))>3276 and cint(right(string,1))>8 then response.write "數據溢出":response.end
end if
end sub
'檢測是否是長整數
複製代碼代碼如下:
sub Is_Lng(string)
if len(abs(string))>10 then response.write "數據溢出":response.end
if instr(string,"-")<1 then
if clng(left(string,9))>214748364 and clng(right(string,1))>7 then response.write "數據溢出":response.end
else
if clng(left(abs(string),9))>21478364 and clng(right(string,1))>8 then response.write "數據溢出":response.end
end if
end sub
以下是一些檢驗函數,需要的朋友可以參考下:
第一種:
一、檢測它是不是整數
複製代碼代碼如下:
functionIs_Int(a_str)
ifnotisnumeric(a_str)orlen(str)>5then
Is_Int=false
exitfunction
elseiflen(str)<5then
Is_Int=true
exitfunction
endif
ifcint(left(a_str,4))>3276then
Is_Int=false
exitfunction
elseifcint(left(a_str,4))=3276andcint(right(a_str,1))>7then
Is_Int=false
exitfunction
else
Is_Int=true
exitfunction
endif