国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > ASP > 正文

asp cint clng的范圍與防止cint和clng的溢出解決方法大全

2020-07-27 13:01:55
字體:
來源:轉載
供稿:網友

首先我們需要了解的是

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


以下是一些檢驗函數,需要的朋友可以參考下:

第一種:
一、檢測它是不是整數 
復制代碼 代碼如下:

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  

如果我們只需要是數子,其它的東西,都可以替換為空,下面這個是武林網站長寫的一個正則,替換非數字的正則
復制代碼 代碼如下:

function replacestr(str)
dim re
set re=new regexp
re.ignorecase=true
re.global=true
re.pattern="/D"
str=re.replace(str,"")
replacestr=str
set re=nothing
end function

下面是上面的調用方法
復制代碼 代碼如下:

id=replacestr(id)
if len(id)>5 then id=left(id,5)
if id<>"" then id=clng(id)
if err.number<>0 Or id="0" then response.redirect "http://m.survivalescaperooms.com"
dim rs
set rs=conn.execute("select id from news where id="&id&"")

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 渝中区| 巢湖市| 济源市| 鄂托克前旗| 吐鲁番市| 阜康市| 成武县| 澄迈县| 洛扎县| 泗阳县| 夏邑县| 大兴区| 定州市| 阿拉尔市| 海丰县| 常熟市| 南和县| 平塘县| 镇平县| 汉源县| 浦江县| 车致| 万州区| 竹北市| 任丘市| 京山县| 文登市| 石城县| 贵州省| 眉山市| 三河市| 石首市| 黄石市| 宣武区| 南华县| 宁陵县| 南康市| 玉环县| 汾西县| 邻水| 绍兴县|