标题:ASP两个比较终极写法
取消只看楼主
ysf0181
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:55
帖 子:914
专家分:2385
注 册:2006-10-4
结帖率:76.71%
 问题点数:0 回复次数:0 
ASP两个比较终极写法
ASP内置函数在比较上一定要判断是否为空后,在用内置函数转换类型进行比较,不然都是通过的。
keai = ""
if  cstr(keai) = 1 then
    response.write 1
end if '错误输出了
keai = ""
if  int() = 1 then
    response.write 2
end if'错误输出了
kong = ""
response.write len(kong)
if len(kong) = 1 then
   response.write 3
end if'错误输出了


response.write "<br>"
'if  LiGeBiJiao_config1(22,"22",0) then
'if  LiGeBiJiao_config1(rs("ceshi_datetime"),"2012-5-1 10:10:10",0) then
'if  LiGeBiJiao_config1(rs("ceshi_datetime"),"2012-5-1 10:10:10",1) then '判断是否为空 空为true
'if  LiGeBiJiao_config1(rs("ceshi_datetime"),2012-5-1 10:10:10,0) then '错误写法
'if  LiGeBiJiao_config1(cstr(),22,0) then '错误写法
'if  LiGeBiJiao_config1(clng(),"22",0) then '错误写法
'if  LiGeBiJiao_config1(int(),"22",0) then '错误写法
if  LiGeBiJiao_config1(rs("ceshi_datetime"),"2",1) then
    response.write 1
end if'正确写法

Function LiGeBiJiao_config1(byval diyige,byval dierge,byval kongpan) 'byval byref kongpan 只能 0 或者 1
   'on error resume next
   'response.write cstr(diyige)&"<br>"
   'response.write dierge
   'response.end
   dim kong11,kong22,tmpkong,tmpType,tmpzhi
   'if kongpan = "" or not isnumeric(kongpan) then
  '    response.write "LiGeBiJiao_config1 调用错误"
    '  response.end
  ' end if
   '//////
   kong11 = 0 : kong22 = 0 : LiGeBiJiao_config1 = false
   '''''
   tmpkong = diyige
  
   Select Case VarType(tmpkong)
   Case 0, 1
     kong11 = 1
   Case 8
     If Len(tmpkong) = 0 Then
        kong11 = 1
     End If
     
   Case 9
     tmpType = TypeName(tmpkong)
     If (tmpType = "Nothing") Or (tmpType = "Empty") Then
         kong11 = 1
     End If
   Case 8192, 8204, 8209
     If UBound(tmpkong) = -1 Then
        kong11 = 1
     End If
   End Select
   if int(kongpan) = 1 then
      if int(kong11) = 1 then
         LiGeBiJiao_config1 = true
      end if
      exit function
   end if
   '''''''//////
   tmpkong = dierge
   Select Case VarType(tmpkong)
   Case 0, 1
     kong22 = 1
   Case 8
     If Len(tmpkong) = 0 Then
        kong22 = 1
     End If
   Case 9
     tmpType = TypeName(tmpkong)
     If (tmpType = "Nothing") Or (tmpType = "Empty") Then
         kong22 = 1
     End If
   Case 8192, 8204, 8209
     If UBound(tmpkong) = -1 Then
        kong22 = 1
     End If
   End Select
  ' response.write kong22
  ' response.end
   '''''''//////
   if int(kong11)=1 and int(kong22)=1 then
      LiGeBiJiao_config1 = true
      exit Function
   end if
   if int(kong11)=0 and int(kong22)=0 then
      'response.write dierge
      'response.end
      'if diyige = dierge then '错误写法
      if cstr(diyige) = cstr(dierge) then
         
         LiGeBiJiao_config1 = true
      end if
   end if
End Function

[ 本帖最后由 ysf0181 于 2013-7-18 15:35 编辑 ]
2013-07-18 14:43



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-417554-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.063883 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved